Skip to content

Instantly share code, notes, and snippets.

@sohooo
Created June 30, 2012 10:38
Show Gist options
  • Save sohooo/3023344 to your computer and use it in GitHub Desktop.
Save sohooo/3023344 to your computer and use it in GitHub Desktop.
rotating rsync backup
#!/bin/bash
# This little script creates incremental rsync backups from a
# list of folders specified in an include list to an external
# harddrive. Backups are important, you know.
#
# Usage
#
# ./sync.sh backup_items.txt
#
#
# The result looks like this:
#
# 20120105-1759
# 20120107-1928
# 20120107-2000
# 20120323-1859
# current -> /Volumes/Phobos/Users/sohooo/20120323-1859
# These rotating backups are possible with rsync's `--link-dest`
# parameter. Look here for more:
# http://www.sanitarium.net/golug/rsync_backups_2010.html
# Settings
# -------------------------------------------
# misc
label=$(date "+%Y%m%d-%H%M")
# backup objects
filelist=$1
# backup paths
backup_path="/Volumes/Phobos/Users/$USER"
inc_backup="${backup_path}/inc_backup-${label}"
full_backup="${backup_path}/${label}"
current_backup="${backup_path}/current"
# Checks
# -------------------------------------------
if [[ ! -f $filelist ]]; then
echo "give me an filelist as parameter"
echo "$0 files_sohooo.txt"
exit 1
fi
if [[ ! -d $backup_path ]]; then
echo "creating backup path $backup_path"
mkdir -p $backup_path
fi
# Backup
# -------------------------------------------
echo "starting $USER's backup of the following stuff:"
cat $filelist
rsync -avzr \
--progress \
--stats \
--link-dest=${current_backup} \
--files-from=${filelist} \
/ $inc_backup
# --delete \
# --delete-excluded \
if [[ $? == 0 ]]; then
echo "syncing successful"
else
echo "syncing error; abort"
exit 1
fi
echo "renaming backup folder"
mv -v $inc_backup $full_backup
echo "linking to current backup"
rm $current_backup
ln -sv $full_backup $current_backup
echo "total backup size"
du -sh $backup_path
echo
echo "your stuff is safe now,"
echo "enjoy this warm and fuzzy feeling"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment