#!/usr/bin/perl # MySQLBackup - by Richard Still # # Full Backup of MySQL files and FTP them to another computer # # What - # This program will look in the default location for MySQL databases on the # Cobalt Raq 3 computer, (if you used the rpm's to install mysql, this # program will work for you) compress those databases, move the compressed # file into another directory, and then FTP that file to another computer # for additional backup. # # Why- # Because the backup scripts written for the cobalt DO NOT back up # your databases. This can be very very dangerous. # # How- # The Net::FTP module is already installed on your Cobalt computer. You can # run this script as a cron job once a day, or once a week. . . or however # often you need to make you feel safe. The name of the file is based on the # date, so unless you make a few modifications you can only back up once a day # # Warnings - # Try to set this to happen at a time when the server is not doing in WRITES # READS are okay, but there is a possibility of data corruption if the tar # happens when information is being written the a table. # Use this at your own risk. But I can tell you that it works very well for # the 8 db's I have on my server! # Oakbox Productions 12/21/2000- Richard Still # This program free to modify, hack, and distribute as long as # this tag comes along for the ride. print " Backing up MySQL databases \n"; %ftpinfo = ( 'username' => "ftp_id", 'password' => "ftp_password", 'host' => "ftp.site.com", 'path' => "/directory/for/backup/files/" ); use Net::FTP; my $ftp = Net::FTP->new($ftpinfo{'host'}) || die "cannot open $ftpinfo{'host'}"; $ftp->login($ftpinfo{'username'},$ftpinfo{'password'}) || die "cannot login with id pass"; $ftp->binary; @date=localtime(time); $day=$date[3]; if($day <10){$day="0".$day;} $month=$date[4]+1; if($month <10){$month="0".$month;} $year=$date[5]+1900; $namer=$year.$month.$day; print " Compressing . . . \n"; # backup mysql db's $gzname="$namer"."mysql"; chdir("/var/lib"); $output=`tar cvzf /home/sites/home/web/$gzname.tar.gz mysql`; print "MySQL db's compressed to $gzname.tar.gz \n"; if ($ftpinfo{'path'}) { $ftp->cwd($ftpinfo{'path'}) || die "path invalid"; } print " FTP to Journalistic . . . \n"; $backupfile="/home/sites/home/web/$gzname.tar.gz"; $filename="$gzname.tar.gz"; $ret = $ftp->put($backupfile, $filename); $ftp->quit; print "MySQL database backed up as $gzname.tar.gz \n";