Home » Questions » Computers [ Ask a new question ]

How do I use rsync to backup my Mac to a NAS?

How do I use rsync to backup my Mac to a NAS?

I need to backup a bunch of directories to my NAS (it basically shows up as a network share in Finder). I don't want to make it bootable, just need to backup a few directories. I'd also like to have it run nightly. I've tried looking at documentation for rsync, but haven't been able to figure it out yet.

Asked by: Guest | Views: 351
Total answers/comments: 2
bert [Entry]

"Does your NAS have an rsync service set up? Some support it (e.g. ReadyNAS). If so, you can do something like this:

#!/bin/sh

DEST=xx.xx.xx.xx::backup/swilliams/
RSYNC_OPTS='-vaC --exclude "".DS_Store""'

/usr/bin/rsync $RSYNC_OPTS --exclude ""build/"" --exclude ""dist/"" --exclude ""*.pyc"" ~/code $DEST
/usr/bin/rsync $RSYNC_OPTS ~/Music $DEST
/usr/bin/rsync $RSYNC_OPTS ~/Pictures $DEST
/usr/bin/rsync $RSYNC_OPTS --exclude ""Virtual Machines*"" ~/Documents $DEST

You'll need to change DEST to the IP address of your NAS, and change paths and stuff to suit.

If you save that as, say, ~/bin/backup.sh (and be sure to do chmod a+x ~/bin/backup.sh) then you can run it nighly using cron. Run crontab -e and add this line:

0 0 * * * $HOME/bin/backup.sh > $HOME/logs/backup.log 2>&1

(0 0 * * * means: run at midnight every day, every month. First column is minutes, so 3am is 0 3 * * *. This will write logs in ~/logs so make sure that directory exists, or put them somewhere else)

If your NAS doesn't support rsync as a service then I think it should work if you change the start to this:

#!/bin/sh

mount_smbfs //user:password@xx.xx.xx.xx/backup /Volumes/backup
DEST=/Volumes/backup

and at the end:

umount /Volumes/backup

(if your share is open, you can leave off user and password)

If you want timestamped backups, you can experiment with the date command. e.g.

DATE=`date +%Y%m%d`

then access $DATE in your script.

If anything here isn't clear to you, just ask."
bert [Entry]

"rsync -av path_to_files path_to_place_on_NAS

run it via cron,
crontab -e
Though you need to know vi for that, and look up crontab syntax.

That works if the files are owned by you. I think you might want the E option (-avE) to grab the resource fork, which is not really used under OS X, as I understand it, but only your classic stuff, which doesn't work any more).

Here are some links, you don't need to mess with the ssh stuff.

simple:
http://www.egg-tech.com/mac_backup/

complex: www.bombich.com/mactips/rsync.html"