I tried this a few months ago when I needed a similar script
I'm sure there is a better way, but it works :)
Thank you
- zeus
----------------------------------------------
#!/usr/bin/perl
######################################################
# config variables
######################################################
$PATH="/usr/local/var";
$MYSQLSHOW="/usr/local/bin/mysqlshow -u ops";
$MYSQLDUMP="/usr/local/bin/mysqldump -u ops";
$BACKUPDIR="/var/backups/mysql/";
$HOST=`hostname`;
chop ($HOST);
$DATE=`date +%Y%m%d`;
chop ($DATE);
######################################################
# Send Summary of program results
######################################################
open (REPORT, "| /usr/sbin/sendmail -f nobody\@inch.com -t -n");
print REPORT "TO: mysqladmin\@inch.com\n";
print REPORT "Subject: Backing up Databases on $HOST $DATE\n";
print REPORT "\n";
open (DATABASES, "$MYSQLSHOW|");
while (<DATABASES>){
# format data
chop;
s/\+/-/ ;
s/\|//g ;
s/^ //g ;
s/-.*// ;
if ( $_ ne "" ) {
$TEMP=`echo $_`;
chop ($TEMP);
######################################################
# BACKUP Databases keep 4 copies
######################################################
if (-d "$PATH/$TEMP" ) {
print REPORT "Backing up $TEMP db on $HOST -
$DATE\n";
chdir ("$BACKUPDIR");
-e "$TEMP.3.dmp" &&
rename("$TEMP.3.dmp","$TEMP.4.dmp");
-e "$TEMP.2.dmp" &&
rename("$TEMP.2.dmp","$TEMP.3.dmp");
-e "$TEMP.1.dmp" &&
rename("$TEMP.1.dmp","$TEMP.2.dmp");
-e "$TEMP.dmp" &&
rename("$TEMP.dmp","$TEMP.1.dmp");
system("$MYSQLDUMP $TEMP > $TEMP.dmp");
}
}
}
print REPORT "\n";
close (DATABASES);
close (REPORT);
-----------------------------------------------------------------------
On Wed, 21 Apr 1999, Xah Lee wrote:
> Is there a way to quickly dump all databases into one directory, with files
> corresponding to each database?
>
> That is, I wish to do call one single script that:
>
> 1. find out what databases are available,
> 2. for each database, do a mysqldump -d database_name to /home/xah
>
> This probably can be written in few lines of Perl. Ideas? (I guess my
> question would be how to get the list of databases.)
>
> Thanks.
>
> Xah
> Home: http://www.best.com/~xah/PageTwo_dir/more.html
> Work: http://www.bpower.com/
>
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail mysql-thread2184@stripped
>
> To unsubscribe, send a message to the address shown in the
> List-Unsubscribe header of this message. If you cannot see it,
> e-mail mysql-unsubscribe@stripped instead.
>
Thank you
- zeus