Perl MySQL backup script.
Posted in dev-sys on September 11, 2006
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.