Skip to content

Instantly share code, notes, and snippets.

@corpix
Created July 12, 2012 12:50
Show Gist options
  • Select an option

  • Save corpix/3097908 to your computer and use it in GitHub Desktop.

Select an option

Save corpix/3097908 to your computer and use it in GitHub Desktop.
Incremental rsync backups
#!/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