The scripts, below, allow you to sync directories or drives easily. Great for backups.
Save the scripts to text files with the .sh extension. Make them executable (chmod +x).
#!/bin/sh if [ $# -ne 2 ]; then echo 1>&2 "USAGE: syncDir.sh /source/dir /backup/dir/" exit 127 fi rsync --delete -av "$1" "$2"
Usage, in terminal window: path/to/syncDir.sh /source/dir/ /backup/dir/. It is recommended to set up mySync.sh, second script below, to execute syncDir.sh and supply the arguments for source directory and target backup directory.
Customize the paths to the syncDir.sh script, your source directory and the target backup directory.
~/scripts/syncDir.sh /Volumes/sourceDir/ /Volumes/backupDir
Execute the script in a terminal window (drag and drop and hit enter, or enter the path to the script and hit enter), or set up a cron job to execute this script on a schedule.
Important note! Seems that sometimes we need to run rsync as superuser, to allow the “–delete” flag to do it’s work deleting or moving files that you have deleted or moved on your source directory. So you can run syncDir.sh as superuser by typing:
sudo ~/scripts/syncDir.sh /Volumes/sourceDir/ /Volumes/backupDir
I recommend testing these scripts thoroughly, with temporary directories and files, before using them on valuable data!