Created
April 8, 2012 16:41
-
-
Save jskripsky/2338382 to your computer and use it in GitHub Desktop.
Script for automated daily rsync-based backups (keeps last 7 days)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### expects file "conf" with configuration | |
### | |
### example: | |
### src="root@mercury" | |
### dirs="/var /etc /root /home" | |
### excludes="/var/log/nagios/spool/checkresults/*" | |
log() { | |
echo `date` "$@" | |
} | |
prefixAll() { | |
prefix="$1" | |
shift | |
for item in $@; do | |
acc="$acc ${prefix}$item" | |
done | |
echo "$acc" | |
} | |
cd $(dirname $(readlink -f $0)) | |
. ./conf | |
exec 1>>log | |
dst="latest" | |
today=`date +%a` | |
yesterday=`date -d "yesterday" +%a` | |
params="--hard-links --delete-during --link-dest=../$yesterday" | |
log "rsyncing $src to $dst (hard-linking to $yesterday)..." | |
rsync -azq --bwlimit=5000 --numeric-ids $(prefixAll "--exclude=" $excludes) $params $(prefixAll "$src:" $dirs) $dst/ | |
log "...done." | |
log "rsyncing $dst to $today (hard-linking to $yesterday)..." | |
rsync -aq $params $dst/ $today/ | |
log "...done." | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment