Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

I also took a look at rsyncx, but can't get that to install. Don't care about Time Machine support either, just need a simple backup.

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
Ok, I ran that, but it took FOREVER. About 10 hours to sync up 300GB of data. Will subsequent runs be quicker after the first one? If not, I'll need to look at another solution. –  swilliams Aug 17 '09 at 15:22
2  
The first time you run it, it will just be a matter of copying all your data. The whole point of rsync is that subsequent runs will be faster because it only needs to transmit changes. Try running it again now -- nothing much should have changed so it should be very quick. If it's not then you may have network issues. –  John Fouhy Aug 17 '09 at 22:01
    
Right, I was just worried because I had already copied all of the data over before (when it was on my prior PC workstation). I just ran it again and it completed quickly. Thank you. –  swilliams Aug 18 '09 at 5:05
add comment

When using rsync for backup the most import options to have a look at are --backup and --backup-dir, without those you are doing a copy, not backup. As with backup you want to keep track of changes, instead of just overwrite them. What I use is this:

#!/bin/sh

RSYNCOPTS="-e ssh --delete --one-file-system --relative --archive -P --verbose --compress --recursive"
BACKUPDIR="/backup/"
BACKUPINCR="${BACKUPDIR}/incr/$(date -I)"
BACKUPROOT="${BACKUPDIR}/root/"
EXCLUDES="--exclude-from /home/juser/.backup-excludes"

# Make sure we use a new incr backup directory on each run
NUM=0
while [ -e "${BACKUPINCR}-${NUM}" ]; do
  NUM=$(($NUM  + 1))
done
BACKUPINCR="${BACKUPINCR}-${NUM}"

for i in /home/ /etc/; do
  rsync $RSYNCOPTS $EXCLUDES--backup --backup-dir="$BACKUPINCR" "$i" "$BACKUPROOT"
done

This gives you a copy in /backup/root/ and a backup of all changed or deleted files in /backup/incr/$DATE-$NUM.

This script uses --one-file-system, so it doesn't cross file system borders and it uses --relative to get the absolute path names preserved.

If you want it extra pedantic, you can add --checksum, that will checksum all files instead of just using the timestamp for skipping. Advantage is that your backup will have a better chance of being free of bit-flips, but it will run for a good while longer.

Another general advise, always use --dry-run when you play around with new option where you are not sure what they do, especially when it comes to --delete and friends, as you don't won't to wipe out your already existing backup by accident.

share|improve this answer
add comment

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%5Fbackup/

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

share|improve this answer
    
Some applications still use Resource Forks. For example Quicken for Mac's backups and main data files become completely useless without the resource fork. –  Chealion Aug 17 '09 at 0:25
add comment

Check out my instructions at http://www.luxgruppe.de/tech/?p=10 and subsequent articles for syncing music and iTunes playlist with your Synology using rsync. iTunes playlist sync: http://www.luxgruppe.de/tech/?p=200

Have fun!

share|improve this answer
    
Greetings, Michael, welcome to SuperUser. Generally speaking, it's best to add at least a short summary of content you link to, just in case the links ever go down. Could you edit your answer to include a little of the information you link to? –  Jonathan Garber Mar 28 '13 at 15:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.