#!/usr/bin/perl # dump_mysql.pl Copyright Peter R. Wood, 2006 # Website: http://prwdot.org/ # You may use this code as long as my name remains # attached to it or any derivative works using it. use strict; my $home = "your home directory"; my $logfile = "name of the logfile"; my $dump_dir = "directory to keep the backup files"; die "ERROR: Please specify the database you wish to back up" unless $ARGV[0]; my $db_prefix = 'prefix for your databases, if you have one'; my $db = $db_prefix . $ARGV[0]; my $db_host = 'localhost'; my $db_user = 'username to access your database'; my $db_password = 'your database password'; my $dump_command = < $dump_dir/$db.dump DUMP my $dump_output = `$dump_command`; open( LOG, ">>$logfile" ) || die "Couldn't open $logfile for appending: $!\n"; print LOG "=" x 80 . "\n"; print LOG scalar( localtime( time() ) ) . "\n"; print LOG "Dumping database $db...\n"; print LOG $dump_output; print LOG "Dump complete.\n"; print LOG scalar( localtime( time() ) ) . "\n"; close(LOG);