Perl MySQL backup script.

I’m in the middle of migrating a lot of websites from one server to another. Here’s a small script I knocked up to take a dump of all the MySQL databases on that machine:

[perl]#!/usr/bin/perl -w
use strict;

my $dumpDir = “/tmp/foo”;
my $dumpUser= “root”;
my $mysqlBin = “/usr/local/mysql/bin”;
my $mysqlPassword = “bar”;

foreach (`ls -F /usr/local/mysql/var`)
{
if (///)
{
chomp;
s//$//; # remove the trailing / now
my $dumpFile = “$dumpDir/$_.sql”;
my $dumpCommand = “$mysqlBin/mysqldump -celqF –password=$mysqlPassword $_ > $dumpFile”;
system $dumpCommand; # or warn “mysqlDump of $_ failed”;
}
}[/perl]

Works for me.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *