Run automated backups to a UNIX server

Jan 18, '06 06:15:00AM

Contributed by: mikebremford

Our office network has a UNIX server which is backed up nightly, and I wanted to take advantage of this to back up the contents of my home directory on my Powerbook when I'm in the office.

I'm sure there are GUI tools that will do this but I wanted it to run in the background, and only when I'm on the office network and when the server isn't too busy. The prerequisites are that you have a UNIX server which you can connect to with SSH without a password (ie you're in the authorized_keys file).

First I created this script, which I named backup, in /usr/local/backup. Within the /usr/local/backup directory, I then created a directory called logs and a file called EXCLUDES.your_username.

The EXCLUDES.your_username file lists the paths you want to exclude from the backup. Mine looks like this, which excludes Cache items, my IMAP mail (it's all on the server already) and the trash:

- /Library/*/Firefox/**/Cache/
- /Library/Safari/Icons/
- /Library/Caches/
- /Library/**/ImapMail/**/*.msf
- /Library/**/ImapMail/**/*.sbd/
- /Library/**/ImapMail/**/INBOX
- /Library/Mail/**/*.imapmbox/
- .Trashes/
- .Trash/
- /Temporary Items/
- .TemporaryItems/
- .Spotlight-V100/
Finally, I ran crontab -e and added the following line to run the backup every weekday at 11am, when I'm probably in the office:
0 11 * * 1-5 /usr/local/backup/backup > /dev/null 2>&1
Logs are stored in /usr/local/backup/logs folder (be sure to create that directory) and are rotated every day. Messages are sent to /var/log/system.log.

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060113043215181