My current iTunes rsync backup script

The other day I was looking for a backup solution for two laptops. While I was unable to get the exact results I was looking for I did create a nice bash script that detects the network, and if on my local network it will mount the share from my Airport Extreme and then rsync the data over.  I am sure there is plenty of room for improvement on this script, but it works quite well.

#!/bin/sh
############################
# iTunes Rsync Cron Script #
############################

ap=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | sed -e "s/^ *SSID: //p" -e d`

if [ $ap == "oxygen" ]
then
clear
echo "You are connected to Oxygen."
echo "Backup will now begin."
echo "Mounting network drive."
sudo mkdir /Volumes/music_backup
sudo /sbin/mount_afp afp://oxygen.local/Storage/ /Volumes/music_backup/
sudo /usr/bin/rsync --exclude .DS_Store --exclude .Trash --stats --progress --inplace --no-owner --no-group -vhlrutD --delete /Users/shelby/Music/iTunes/iTunes\ Media/Music/* /Volumes/music_backup/Music/shelby/
echo "Unmounting network drive."
sudo /sbin/umount /Volumes/music_backup
echo "Backup is complete."
else
clear
echo "You are not connected to Oxygen. Music will not be backed up at this time."

3 thoughts on “My current iTunes rsync backup script”

  1. You don’t need to mount the backup volume, because rsync can talk to the server directly. This is not only more straight forward, it also avoids any potential issues with mounting/unmounting the server volume. Just read the man page of rsync to find out more.

    • In the past I have chosen not to mount the destination drive, but in this case I got much faster transfer speeds rather than doing it over ssh.  I am defiantly open to suggestions on better rsync flags to use.

Comments are closed.