Created
July 12, 2012 12:50
-
-
Save corpix/3097908 to your computer and use it in GitHub Desktop.
Incremental rsync backups
This file contains hidden or 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/bash | |
| trap "echo Exited!; exit;" SIGINT SIGTERM | |
| SOURCE="/home/" # Path to data needs backup | |
| YESTERDAY=`date -I -d "1 day ago"` | |
| TODAY=`date -I` | |
| SERVER="user@server" | |
| STORAGE="/storage/backup" | |
| LAST_LINK=`ssh $SERVER "ls -c $STORAGE | head -n 1"` | |
| if [ -z $LAST_LINK ]; then | |
| LINK="$STORAGE/$YESTERDAY" | |
| else | |
| LINK="$STORAGE/$LAST_LINK" | |
| fi | |
| TARGET="$STORAGE/$TODAY" | |
| MAX_RETRIES=10 | |
| # | |
| # Configuration end | |
| # | |
| i=0 | |
| # Set the initial return value to failure | |
| false | |
| while [ $? -ne 0 -a $i -lt $MAX_RETRIES ] | |
| do | |
| i=$(($i+1)) | |
| rsync -aqhe ssh --exclude=".gvfs*" --exclude="gvfs*" --delete --link-dest="$LINK" "$SOURCE" "$SERVER:$TARGET" | |
| done | |
| if [ $i -eq $MAX_RETRIES ] | |
| then | |
| echo "Hit maximum number of retries, giving up." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment