My rsync Backup Script

This code will look for the differences between folders, replace the old files with the new files after moving the old ones into a separate folder, and display the activity. It’s stored in /Users/GG/bin/ and simply named backup:

if [ $# -ne 2 ]; then
echo 1>&2 Error, Usage: $0 sourcePath destDir
exit 127
theDate=`date '+%y%m%d%H%M%S'`
echo "------------------------------------------------------------" > "$scriptOut"

echo; echo; echo "$1$2 -> $theDate" >> "$scriptOut"
rsync -ablPvz --backup-dir="$theIncr" --delete --progress "$1$2/" "$destPath/$2" >> "$scriptOut"

echo "------------------------------------------------------------" >> "$scriptOut"

cat "$scriptOut"
exit 0

Run these lines in a BBEdit worksheet.

backup “/Users/GG/” “bin”
backup “/Users/GG/Documents/” “Save”
backup “/Users/GG/Documents/” “Databases”
backup “/Users/GG/Library/” “Application Support”
backup “/Users/GG/Library/” “Mail”
backup “/Volumes/Cornucopia/Library/” “WebServer”

Command-z to get rid of the progress reports.

I remember (wrote this script years ago) that there was something critical about one slash character in the rsync parameter list to get the behavior exactly right. Also, although the results for this user are fine, the script’s execution gives “Permission denied” error messages for directories belonging to others.


Published by


computer programmer, group organizer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s