Archive

Posts Tagged ‘rsync’

Backing up an OSX profile to a linux server with rsync

December 31st, 2008 bed 3 comments

TimeMachine is some nice software, but its overkill for me. I’ve previously written about this and how I put together a rsync solution and why I did so. In the case that anyone might be interested in doing the same, here is my setup.

Linux Server
I have a gentoo linux server, but this should be a mostly generic rsync server setup. My rsyncd.conf looks like this

# /etc/rsyncd.conf
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
use chroot = yes
read only = no
uid = bed
gid = bed
hosts allow = 192.168.42.0/24

[bed-backup]
        path=/mnt/backup/bed
        comment = Beds Backup

and of course rsyncd is in my /etc/init.d and starts automatically at boot.

OSX
I have a simple bash script that I can run that will backup the contents of my home directory, called backup_bed.sh. This will turn sleep off, make sure the network is available (as the machine may have been woken from sleep) and then do the backup.

#!/bin/sh
#Bed's rsync backup script

echo `date` Beds Backup > last_backup.log
echo `date` ------------- >> last_backup.log
echo `date` Script Starting at `date` >> last_backup.log

# turn off system sleep
pmset -a sleep 0 2>&1 >> last_backup.log
echo `date` Turned off sleep >> last_backup.log

echo `date` ------------- >> last_backup.log

# wait for network to show up
pingcount=0
trycount=1
failflag=0
while [ $pingcount -eq 0 ]
do
    echo `date` Waiting for network... $trycount >> last_backup.log
    pingcount=$(/sbin/ping -c 3 -o bedentoo | grep "received" | awk -F',' '{ print $2 }' | awk '{ print $1 }')
    trycount=`expr $trycount + 1`
    if [ $trycount -eq 11 ]
    then
        echo `date` network fail - giving up >> last_backup.log
        failflag=1
        pingcount=-1
    fi
done

if [ $failflag -eq 0 ]
then
        #do rsync
        echo `date` RSync started.  >> last_backup.log
        /usr/bin/rsync -a -x -S -v -v --progress --exclude-from=/Users/bed/scripts/backup_excludes.txt  /Users/bed/ bedentoo::bed-backup 2>&1 >> last_backup.log
        echo `date` RSync finished.  >> last_backup.log
fi

#turn system sleep back on
echo `date` ------------- >> last_backup.log
pmset -a sleep 30 2>&1 >> last_backup.log
echo `date` Turned on sleep for 30 min >> last_backup.log

echo `date` Script Finished  >> last_backup.log
echo `date` ------------- >> last_backup.log

I exclude non-essential stuff from my backup, notably temporary files and my virtual machines. These excludes are specified in the backup_excludes.txt file:

- .Trash
- Downloads
- temp
- Caches
- Parallels

And finally, the backup_bed.sh script is run every morning at 8am by launchd. The easiest way to configure launchd is with a nice GUI tool called Lingon. This is created as a User Daemon.

Finally my OSX is configured to automatically wake up a minute before the launchd runs (via System Preferences -> Energy Saver -> Scheduler). If for some reason the machine is actually off, launchd will run the script as soon as it can when the machine is next booted. (launchd is a very nice system).

One note of warning, this setup will not properly support Classic MacOS resource forks. These are nolonger used in OSX, however if you maintain a classic MacOS enviroment, you can backup to a OSX server (not a linux server) and use the -E option of OSX’s rsync.

Categories: Tech Talk

Backups

August 19th, 2008 bed No comments

Before becoming a Mac-convert, my backup procedure was almost non-existent. Every six to twelve months I would burn a CD or DVD with my most important stuff on it. I’ve been rather lucky that I’ve never had a hard-drive failure – its happened to most people I know at least once.

After turning to the Apple-Dark-Side they made it too easy. To not do a backup really required effort. Stick a USB drive in, turn on Time Machine… and you have a regular automatic backup procedure.

Of course I didn’t want to backup to USB drive. I have my and K’s stuff to backup, and an Ubuntu file server with a nice 400GB drive to hold the files (lets not discuss off-site backups, move along…). Now while Time Machine supports backing up to a network drive, they limit it to Apple’s own products, or a drive hosted by Mac OSX 10.5. Capitalistic goals aside, there is a very good reason for this. Apple added some extensions to AFP to safely handle network dropouts during the backup process. These extensions are required to safely protect your backups from becoming corrupted.

Now if you are pretty confident that your network isn’t going to drop out during a backup, you can configure Time Machine to allow an unsupported network drive, and backup to your SMB shared network drive. Easy. So thats what I did.

This has worked flawlessly with K’s iMac. My MacBookPro however, was more complicated. Because its a laptop, I often run on wireless when I’m downstairs in-front of the tv. When I go upstairs, I’ll plug in the Ethernet for optimal speed and turn off wireless. Of course I never paid attention to see if Time Machine was currently working when I did this. It was often running and every so often I would corrupt my backup sparseBundle and had to start all over again.

So I finally gave up on Time Machine for my laptop. I still wanted the automated backup however – but I don’t care about incremental backups, I’ve never (famous last words maybe…) wanted to go back to a previous version of a file. I just care that the current version is backed up in-case my drive dies.

This is where I love that the best computer UI is built on-top of the best OS core… unix. A simple installation of rsync on my Ubuntu file server, a simple shell script on my laptop (rsync is installed by default with Leopard) and I’m mirroring the folders I want. Then a simple configuration of my system to wake up at 3am and run my script and I’m automated. Too easy.

Categories: Personal, Tech Talk