Voytek wrote: > <quote who="Jacinta Richardson"> > > thanks, Jacinta > > ahem, you assume I'm somewhat perl-literate, beyond knowing how to > paste'n'save... I'm not...
My apologies. Although I do find that it's usually better to to assume that people who are asking about an existing Perl program are more often Perl literate than they are Perl newbies. :) > unless( unlink("$backuppath/$database-$oldyear$oldmonth$oldday.sql.gz"); Ah. Remove the trailing ; and replace with a ) { > 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"; You probably don't need to to select *. But it doesn't hurt. > 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"; > } You might want to make the above error somewhat more useful. Perhaps: die "Mysqldump failed for some reason."; just so that you know... I've reindented. Hopefully you just lost the indentation in your cut and paste. > # 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"; > } You probably want to change this error message as well. die "Failed to gzip file."; > # Now that you're fairly certain that the new backup has worked... > unless( unlink("$backuppath/$database-$oldyear$oldmonth$oldday.sql.gz"); This should be: 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"; > } On further thought you proably want to change this die to the following: warn "Failed to remove $database-$oldyear$oldmonth$oldday.sql.gz: $!"; as failing to delete might not be important enough to stop doing all the backups. All the best, Jacinta -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | [EMAIL PROTECTED] | (il),-'' (li),' ((!.-' | www.perltraining.com.au | -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html