<quote who="Jacinta Richardson">
thanks, Jacinta
ahem, you assume I'm somewhat perl-literate, beyond knowing how to
paste'n'save... I'm not...
the script was kindly given to me in the past by a slugger
paste'n'save gave me an error on the last '}' in your additions, after
chopping it, I'm getting:
# perl mysqlbackup-day.pl
syntax error at mysqlbackup-day.pl line 61, near ");"
Execution of mysqlbackup-day.pl aborted due to compilation errors.
line 61 is:
unless( unlink("$backuppath/$database-$oldyear$oldmonth$oldday.sql.gz");
script now is:
-------------------
#!/usr/bin/perl
use DBI;
use Mysql;
use Date::Pcalc qw(:all);
$DB_Host = "localhost";
$DB_Name = "mysql";
$DB_User = "backup";
$DB_Password = "password";
$backuppath = "/backup/mysql";
$myoffset = -3; # set the number of days back to delete. Basically -number
of days you wish to keep logs rotating for.
my $dbh =
Mysql->Connect("$DB_Host;database=$DB_Name;",$DB_User,$DB_User,$DB_Password)
or die "$Mysql::db_errstr";
($year,$month,$day) = Today();
if (length($day)==1) {
$day = "0$day";
}
if (length($month)==1) {
$month = "0$month";
}
($oldyear, $oldmonth, $oldday) = Add_Delta_YMD($year, $month, $day, 0, 0,
$myoffset);
if (length($oldday)==1) {
$oldday = "0$oldday";
}
if (length($oldmonth)==1) {
$oldmonth = "0$oldmonth";
}
$dbh->selectdb(mysql) or die "$Mysql::db_errstr";
my $sth = Query $dbh "SELECT * FROM db" or die "$Mysql::db_errstr";
while( my ($ignored, $database) = $sth->fetchrow() ) {
print "$database\n";
# Make the backup
system("mysqldump --opt $database -u $DB_User --password=$DB_Password ".
" > $backuppath/$database-$year$month$day.sql");
# Handle any errors
if($?) {
# something went wrong... try to guess what.
die "some error as appropriate";
}
# Do the compression
system("gzip", "$backuppath/$database-$year$month$day.sql");
# Handle any errors
if($?) {
# something went wrong... try to guess what.
die "some error as appropriate";
}
# Now that you're fairly certain that the new backup has worked...
unless( unlink("$backuppath/$database-$oldyear$oldmonth$oldday.sql.gz");
# something went wrong... try to guess what.
# This could just be that the file doesn't exist.
die "if you think it's appropriate";
}
undef $sth;
undef $dbh;
---------------------------
--
Voytek
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html