Skip to content

Instantly share code, notes, and snippets.

@gglanzani

gglanzani/backup.sh

Created Aug 5, 2011
Embed
What would you like to do?
My rsync script to backup my data
#!/bin/bash
# backup-script for rsync/osx
#
#
#
# ----- Set Default Parameters -----
#
# folders to backup..
src_folders="/Users/gio/ /Library"
sc="scutil --get ComputerName"
# backup-target
if [[ $($sc | grep spar) == "spartacus" ]]; then
dest_folder="/Volumes/data/MacBookPro_backup"
fi
if [[ $($sc | grep tele) == "telemaco" ]]; then
dest_folder="/Volumes/data/iMac_backup"
fi
# location of hfs-enabled rsync-command
rsync_cmd="/usr/local/bin/rsync"
# excluded folders, separate with space, terminate with "/"
exclude_folders="Safari/Icons/ Caches/ .Trash/ *.app Steam/"
# rsync options
rsync_options="-aNHXsR --fileflags --delete-before --force-delete"
#
# ----- Check if params are reasonable -----
#
if [[ $rsync_cmd == "" ]]; then
echo "no command given"
exit 1
fi
if [[ ! -x $rsync_cmd ]]; then
echo "$rsync_cmd is not executable"
exit 1
fi
if [[ ! -d $dest_folder ]]; then
echo "$dest_folder is not a directory"
exit 1
fi
if [[ ! -w $dest_folder ]]; then
echo "$dest_folder is not writable"
exit 1
fi
# build exclude-options
for path in $exclude_folders; do
exc_options="$exc_options--exclude \"$path\" "
done
# build cmdline
cmd="$rsync_cmd $rsync_options $additional_options $exc_options"
#
# ----- do rsync -----
#
for path in $src_folders; do
cmd_here="$cmd $path $dest_folder"
echo `date`" >> calling rsync for $path "
eval $cmd_here
echo " "
done
echo "backup complete."
echo "Now unmounting disk"
diskutil umount /Volumes/data
zpool export data
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment