File:  [Local Repository] / sludge_scripts / backup.pl
Revision 1.1: download - view: text, annotated - select for diffs
Wed Jun 22 20:12:58 2011 UTC (13 years, 4 months ago) by nick
Branches: MAIN
CVS tags: HEAD
Due to problems in bash (or my scripting knowledge) I was having ongoing problems with spaces in the directory names.  I decided to convert the shell script to a wrapper to launch a perl script that actually calls rsync.  The shell wrapper still handles compressing and deleting old logs.

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $VERSION	= "\$Id\$";
my $REMOTE	= "nick\@demandred.dyndns.org";
my $OPTIONS	= "-avxz\ -e\ ssh\ --delete";
my $RSYNC	= "/usr/bin/rsync";
my $LOGDIR	= $ARGV[0] || "/home/backup/logs";
my $DATE	= `date +%Y%m%d`;
my $BACKUP_DIR	= "/home/backup/backups";

my %DIRS = (
		demandred => [
			"/home/nick/database-backup.dump.gz",
			"/home/nick/database-backup.dump.yesterday.gz",
			"/home/nick/DroidBackups",
			"/home/cvs",
			"/home/nick/bbs",
			"/home/nick/notes",
			"/home/httpd",
			"/home/nick/Documents",
			"/home/nick/mail",
			"/home/nick/mail-backup",
		],
		winshare => [
			"/home/winshare/Documents",
			"/home/winshare/Pictures",
			"/home/winshare/Receipts",
			"/home/winshare/Shared\\ Docs",
			"/home/winshare/Backgrounds",
		],
		lanfear => [
			"/home/backup/systems/lanfear/home/nick/Documents",
			"/home/backup/systems/lanfear/home/nick/Receipts",
			"/home/backup/systems/lanfear/home/nick/Nick\\'s\\ Pictures",
			"/home/backup/systems/lanfear/home/nick/projects",
		 	"/home/backup/systems/lanfear/home/nick/notes",
		],
);

foreach my $backup ( keys %DIRS ) 
{
	foreach my $dir ( @{ $DIRS{$backup} } ) 
	{
		my $dest    = $BACKUP_DIR . "/" . $backup;
		my $command = "/usr/bin/rsync $OPTIONS \"$REMOTE:$dir\" $dest";
		print "Backing up $REMOTE:$dir to $dest\n$command\n";
		system( "mkdir -p $backup" );
		system( $command );
	}
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>