This is just a short script to utilise the mysqldump utility. The reason I am posting this is to double check with you Monks that I haven't inadvertantly made any boo-boos. My last posting resulted in many good points being raised that I hadn't even considered, and I always get nervous when I use the system() call {shudder}. So any feedback (•s etc) most welcome. I remain all ears and again wish to thank you all for all that I have learned to date.

Update:

Thanks to podmaster for mentioning this, there is a security flaw in so much as a ps could be run showing the password.

#!/usr/bin/perl -w use strict; # Ideally should be called daily using cron my $BAKDIR = '/path/to/bak/dir'; my @DBS = qw/foo bar baz/; my $DBUSER = 'user'; my $DBPASS = 'password'; my $DAYS_TILL_UNLINK = '31'; # Error traps unless (-e $BAKDIR) { mkdir ($BAKDIR, 0600) || die "Can't create $BAKDIR $!\n"; } unless (-d $BAKDIR) { die "$BAKDIR is unavailable\n"; } my ($day, $mon, $year) = (localtime(time))[3,4,5]; $mon += 1; $year += 1900; my $date = "$year.$mon.$day"; # Iterate through Dbs to be backed up foreach my $db (@DBS) { my $cmd = "mysqldump $db -u$DBUSER -p$DBPASS > $BAKDIR/dump.$db.$d +ate"; system($cmd) == 0 || die "Can't dump $db: $!\n"; } # Remove old backups if older than $DAYS_TILL_UNLINK chdir "$BAKDIR" || warn "Can't change directory to $BAKDIR $!\n"; my $db; $db = <dump.*>; while ($db = <dump.*>) { if (-M $db > $DAYS_TILL_UNLINK) { unlink ("$db"); } }