Do you have critical data on one or more computers that you would not want to lose if your hard drive crashes? Is that data actually backed up or are you praying that your hard drives live forever? There are several methods available to back up that data. I have decided to use an existing computer in my network as a central backup server and I will share the details of my setup for anyone else to duplicate.
If you are running Windows, first install the operating system. Once that is complete (including all updates), download and install Cygwin. Make sure that you include OpenSSH, rsync, and optionally rxvt (a shell). OpenSSH and rsync are required for the backup solution. I prefer rxvt as my graphical shell in Cygwin over the default because it looks better and is more easily resizable. You can create a new shortcut for Cygwin (which I call Cygwin+) that will run this command:
C:\cygwin\bin\rxvt.exe -fn "Courier New-15" -bg black -fg grey -title Cygwin -e /usr/bin/bash --login -i
Once Cygwin is installed, you may want to enable the SSH server if you plan on connecting to the backup
files remotely or pushing backups to this host. To install the server, run ssh-host-config in
a Cygwin shell. Follow the prompts to configure the server. Then run net start sshd to start
the service.
I am using several different methods to actually back up my data, depending on the specific needs of the source server. Basically, my data backups fall into 3 different categories:
man rsync to learn the specific options of the program.
I use this syntax to back up a directory from the host 'fry' to my backup server, which is named 'bender'.
rsync -av DataDir Administrator@bender:/cygdrive/c/Backups/fryThat will copy the entire DataDir and all of its subdirectories to 'bender', in the new location C:\Backups\fry\DataDir. Note that you do not specify the source directory name again in the destination; it gets created automatically. Also, the "/cygdrive/c" notation is how Cygwin identifies the C:, because normal Unix file systems do not have the notion of drive letters. If you wanted to put the files on D:, you would use /cygdrive/c.
rsync -av Administrator@leela:/cygdrive/c/DataDir /cygdrive/c/Backups/leela
The script that runs on the web server requires Perl. You will need to edit the script to include your personal information, like where the backups should be stored, the database names/users/passwords, etc.
#!/usr/bin/perl -w
use strict;
use DirHandle;
my $backupDir = "/home/zbrannigan/db-backups";
if (! -d $backupDir) {
print ". Backup dir does not exist ($backupDir)\n";
exit;
}
# Determine the actual dir to use
my @t = gmtime();
my $date = sprintf("%4.4d-%2.2d-%2.2d", $t[5] + 1900, $t[4] + 1, $t[3]);
my $num = 1;
$num++ while (-e "$backupDir/${date}-$num");
my $dir = "$backupDir/${date}-$num";
mkdir $dir;
if (! -d $dir) {
print ". Cannot create directory: $dir\n";
exit;
}
chdir $dir;
`mysqldump --opt -pdingus -h db.doop.gov -u zbrannigan zap | gzip -9 > zap.mysqldump.gz`;
`mysqldump --opt -pwingus -h db.doop.gov -u kkroker kiff | gzip -9 > kiff.mysqldump.gz`;
# Cleanup directories
my $dh = new DirHandle($backupDir);
if (! defined $dh) {
print "$dir Cannot open $backupDir for cleaning.\n";
exit;
}
my @dirs = ();
while (my $f = $dh->read) {
if (-d "$backupDir/$f" && $f ne '.' && $f ne '..') {
push @dirs, $f;
}
}
$dh->close;
chdir $backupDir;
my @sorted = sort {$b cmp $a} @dirs;
for (my $i = 10; $i < scalar(@sorted); $i++) {
my $d = $sorted[$i];
if (length($d) > 10 && -d $d) {
`rm -rf $d`;
}
}
print "$dir\n";
You can run this script remotely through SSH to build the snapshots and then use the rsync pull command to pull the entire 'db-backups' directory with all of the snapshots.
#!/bin/bash
BackupDir=/cygdrive/c/Backups
ScriptDir=$BackupDir/scripts
CurrentDir=`pwd`
# First, check if the disabled file exists
if [ -f $ScriptDir/disabled ] ; then
exit;
fi
# Backups
# doop.gov
cd $BackupDir/Doop.gov
rsync -av --exclude 'doop.gov/kkroker' zbrannigan@www.doop.gov:doop.gov .
rsync -av zbrannigan@www.doop.gov:util .
# Run the MySQL snapshot and rsync it
ssh zbrannigan@www.doop.gov /home/zbrannigan/util/db-backup.pl
rsync -av zbrannigan@www.doop.gov:db-backups .
# leela
cd $BackupDir/leela
rsync -av Administrator@leela:/cygdrive/c/DataDir .
rsync -av Administrator@leela:/cygdrive/c/mp3 .