The adventures of Michelle, Aidan, Josie and Ernest
millan.info /
System Backup Script: Part Two
Back in June, I posted a bash script I use weekly to backup my Powerbook onto my Linux server. Basically, the script went through two steps. The first step created tarballs of various text based configs in places such as /etc and ~/Library and the second step went on to 'rsync' or mirror various directories over to my Linux box.

Beyond this, I also set up Josie's Windows XP box to sync over her 'My Documents' folder to my Linux box on weekly basis. To do this, I had two options. Either install Cygwin and configure a cron to perform the task via rsync or make use of a Windows-friendly GUI-based application. I decided to go with the later and found Rundegren's Instant Backup to be perfect for the task. "When in Rome..." ;-)

Once everything was backed up from our personal machines to the Linux box I was happy. My final concern revolved around the files that were only stored on the Linux box, such as our massive photo collection. Clearly, these files needed to be mirrored onto another drive on some routine basis. So with this in mind, I made use of yet another bash script and this time, the mighty Crontab.

Here is the backup.sh script:

#!/bin/bash
######################################################
export buDir="Now backing up..."

echo -e "\n$buDir '/etc'";
sudo tar -czf {destDir}/etc_$(date +%Y%m%d%-H%M%S).tar.gz /etc;

echo -e "\n$buDir '/var/log'";
sudo tar -czf {destDir}/var_log_$(date +%Y%m%d%-H%M%S).tar.gz /var/log;

echo -e "\n$buDir 'pictures'";
rsync -a --delete {sourceDir} {destDir};

echo -e "\n$buDir 'your external web site'";
wget -q --mirror ftp://{username}:{password}@{site_ftp_url}/ -P {destDir};

echo -e "\nNow repairing permissions..."
chmod -R 751 {destDir}/backup;
chmod -R 750 {destDir}/pictures;

echo -e "\nAll updates have been completed!";
######################################################
# end of backup.sh

Beyond just backing up local files, the great thing about this script is that it also performs a wget mirror of my external sites and then wraps thing up with some handy-dandy directory permission clean up. :-)

Lastly, I setup a cron job to run my backup.sh script every Friday at noon.

% crontab -e

00 12 * * 5 {path_to_my_scripts}/backup.sh



Enjoy!
Posted by Ernest Millan at 11:38 AM