Automated backup

September 30th, 2009 at 12:48 · Filed Under Blogging, Call Me a Geek, Computing, Linux, Mac OS X, Software Development, Solaris · Comment 

Since August 18, my software development work has been picking up its pace and I have checked in more works more often, at least five times on single productive day. Ever since, I have been manually backing up Subversion directory using tar. My project server is fornax.

Fornax is a 6-year old PC running Ubuntu. It wasn’t working properly due to the cooling fan in its power supply unit. Until about two weeks ago, I replaced the old fan. I am not very confident about the replacement because it is a third party part and the replacement isn’t as good as expected, but it works. I have to shut it down every night before going to bed.

So, the last thing before I go to bed is to backup the svn directory and then shutdown the server. I am quite fed up with this extra manual works. Last night, before going to bed, I decided to automate this process. And I did it this morning.

I wrote a simple bash shell script to do the backup. I cron it so that the process will start automatically at 2300 hours and then shutdown.


#!/bin/bash

BACKUPFILE=/tmp/backups/svn-$(date +%Y%m%d).tar.gz

rm /tmp/backups/svn-*.gz
tar -cj /svn > $BACKUPFILE
for COMPUTER in host1 host2
do
   scp $BACKUPFILE user@$COMPUTER:Desktop/
done
/sbin/shutdown -h +5

UPDATE (05/10/2009): I setup a password-less ssh login so that no password is required for scp (secured copy). Now, after the backup, the backup file will be copied automatically to two other computers for safe keeping.