Backing up an OSX profile to a linux server with rsync

  • By bed
  • Wed 31 December 2008

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/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.

tags: OSXrsync