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:

#!/bin/sh
if [ $# -ne 2 ]; then
echo 1>&2 Error, Usage: $0 sourcePath destDir
exit 127
fi
theDate=`date '+%y%m%d%H%M%S'`
destPath="/Volumes/Motherlode/Backup"
theIncr="$destPath/$2-$theDate"
scriptOut="$destPath/progress.txt"
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.

Advertisements

Published by

macenable

computer programmer, group organizer

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s