Mac Auto-mount NFS and Backup iTunes

A while back I bought a D-Link ShareCenter DNS-320 network attached storage because it was on sale ($109 SGD). The performance is pretty poor (writes around 20 MB/s), but it has some useful features:

  • Supports Time Machine backups (requires a firmware update for OS X 10.7+).
  • Share a USB printer over the network—I have a WiFi enabled Canon MP495, but am always getting connection issues, this USB sharing will hopefully fix this.
  • Runs Linux so you can do some interesting things.
  • Can operate as an iTunes server.
  • Can access it from anywhere over the internet.

My main uses for it currently are:

  • Time Machine backups.
  • Destination for a friend's CrashPlan backups.
  • Backup/share photos.
  • Backup music and use this backup as an iTunes server's source media.

To do the above automatically I have an AppleScript which runs at login and mounts the network drive and then executes a shell script which runs an rsync backup. All of the required software is already on your Mac and you don't need to install anything extra.

Mount Script MountNFS-Volume1.app

try
	mount volume "afp://192.168.1.101/Volume_1"
	delay 10
	tell application "/Volumes/Volume_1/rsynced/sync.app" to activate
end try

Script Notes:

  1. Use Automator with the Run AppleScript action and save it as an MountNFS-Volume1.app somewhere on your Mac e.g. Documents.
  2. Make sure your NAS has a fixed IP e.g. 192.168.1.101
  3. If the NAS is offline you will eventually get an alert box saying that the volume could not be found. This is a system message and you cannot tell mount to hide it i.e. you will manually have to dismiss the error.
  4. After mounting I have a delay and then run another script (sync.app) to perform my rsync backups.
  5. You need to add a login item to run MountNFS-Volume1.app.

Backup Script sync.app

Use rsync to backup your pictures and iTunes libraries sync.app

rsync -rt --force --delete --exclude "~/Music/iTunes/iTunes Music/Automatically Add to iTunes" --size-only ~/Music/iTunes "/Volumes/Volume_1/rsynced/Music/" > ~/Documents/rsynclog-itunes.txt 2>&1

rsync -rt --force --size-only ~/Pictures "/Volumes/Volume_1/rsynced/" > ~/Documents/rsynclog-pictures.txt 2>&1

Script Notes:

  1. Use Automator with the Run Shell Script action and save it to /Volumes/Volume_1/rsynced/sync.app.
  2. Keep an eye on the log files ~/Documents/rsynclog-itunes.txt and ~/Documents/rsynclog-pictures.txt for any errors.
  3. Some guides recommend using rsync -aE --delete or rsync -av --force --delete --size-only. Both of these would sometimes give me errors when backing up my iTunes library rsync: chgrp failed: Operation not permitted (1) or rsync: delete_file: unlink failed: Invalid argument (22), not sure what is going on, possibly something to do with the network file system not supporting something. Probably a good idea to try using one of the -a arguments so that all of the file attributes are preserved and keep an eye on the error logs.
  4. For historical reasons I have a mount and sync script, you could easily just use one script.

Next Steps

It would be nice if I could get CrashPlan running directly on my NAS and eliminate the need for my computer to be on. The DNS-320 runs Linux, therefore it can run an ARM version of Java and apparently a headless version of CrashPlan. Will be looking into this shortly.