Dec 15 2008

Easy backups in OS X

Published by at under technology

I’ve settled on the killer combination for easy backups to a NAS on OS X, and it involves installing no software.  It’s a combination of rsync, and scheduling with launchd.

The first step is getting your rsync command working.  I like it because it allows you to maintain a mirror of your files on the remote drive, and only copies over files that have changed when you run it.  Being a built-in command, it’s also a lot sleeker than installing a GUIed app of questionable speed. I mirror various key folders like this:

rsync -aSv --delete --progress ~/Pictures/ /Volumes/MACSHARE/rsync/Pictures > ~/scripts/logs/pictures.txt

There’s a number of options you can look at through the rsync man pages. I store my rsync commands in a file called backup.shIn order to Automate this process, you can set up a launchd task. Launchd replaced a lot of unix apps like cron on more recent OS X releases. You need to set up a plist file that points to your backup script and tells it how often to run, and store it in ~/Library/LaunchAgents/. Here is the file I use (you can call it something like com.backup.plist):





        Label
        ryan.backup.script
        LowPriorityIO
        
	ProgramArguments
		
			/Users/ryan/Scripts/backup.sh
		
        StartCalendarInterval
        
        	Hour
		2
		Minute
		0
        


You can look at the Apple man pages for launchd to determine what other arguments you can use. This one is set to run at 2am. You can also do some cool things such as running a script when a watched directory changes.Once you have your plist file, you have to register it with launchd.  In the LaunchAgents directory at the terminal, you can type launchctl load com.backup.plist A trick I used to make sure the scheduling was working, is to point to an alternative script (test.sh) containing say hello. I set the schedule a few minutes ahead and made sure the speakers were on to hear it say “hello”.

No responses yet

Leave a Reply