Vertigo72

Just another WordPress.com weblog

How to backup from webserver to home computer (Mac)

leave a comment »

Short version: wake-up, rsync, kill, sleep. We have to do a nightly backup of our website. We have ssh access to the server, good ADSL connection and a big external drive connected to a Mac laptop, so we decide to do a nightly backup from the server to the external drive. The backup runs when there is no much load and traffic on the server. It starts at 2:00 and should end at last at 5:00, otherwise we kill it. The laptop wake-up at 1:59, starts the backup then go sleep when the backup is finished or interrupted.

Backup script

The backup script uses rsync to mirror the website directory from the server to the home computer. We need to have the rsync installed on both server and the home computer. We also need to configure ssh to connect without password. The log of transferred files is written into the log-file The script uses the pmset sleepnow to put the computer back in sleep mode when the rsync command is ended (finished or interrupted). In order to end the backup at 5:00 the script wait 10800 seconds (3 hours) using sleep, then kill all rsync processes, if any, with killall rsync.

#!/bin/sh
(rsync -v --rsync-path="nice rsync" --times --recursive --stats --rsh=/usr/bin/ssh me@server:/dir/to/backup /local/backup/dir > /path/to/log-file.log; pmset sleepnow)&
sleep 10800
killall rsync

Crontab

Next, we have to put this script into crontab: type crontab -e and schedule the execution of the script at 2:00 every night:

0 2 * * * /path/to/backup-script.sh >& /dev/null

Schedule the wake-up

Finally, we should be sure that the computer will wake-up at 2:00 to allow the script to run. We schedule a wakup using the same pmset command:

sudo pmset repeat wake MTWRFSU 01:59:00

That’s all! You can now put your mac (and you) in sleep mode in the evening – your backup will run automatically during the night.

Advertisement

Written by vertigo72

September 25, 2008 at 2:12 pm

Posted in How To

Tagged with , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.