Re: MySQL backup software

From: Date: Wed, 27 Oct 2004 14:18:58 +0000
Subject: Re: MySQL backup software
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-37045@lists.php.net to get a copy of this message
Perry, Matthew (Fire Marshal's Office) wrote:
Does anyone know a free MySQL backup program to schedule regular backups? Hi Mathew, i made an litle script to do that.
mysqlbk.pl Desc: This script made and mysql rotative backup fron sunday to sunday --------------------------------------------------------------------------------- #!/usr/bin/env perl use strict; use File::Find (); use POSIX qw(strftime); use DBI; my $day = strftime "%A", gmtime; my $str = POSIX::strftime( "%A, %B %d, %Y", localtime(time)); my $path = "/home/lmorales/backup/mysql/".$day; #print "Creando directorio ".$path."\n"; eval{ system("/bin/rm -r ".$path); system("/bin/mkdir ".$path); }; my $dbh = DBI->connect("DBI:mysql:database=mysql;host=localhost",
                       "root", "yourpasswd",
                       {'RaiseError' => 1});
my $sth = $dbh->prepare("show databases"); $sth->execute(); print "Respaldo diario: $str\n"; while (my $ref = $sth->fetchrow_hashref()){ print "Creando Respaldo para Data Base : $ref->{'Database'} \n"; system("/usr/bin/mysqldump -uroot -pag10nus --lock-tables $ref->{'Database'} > ".$path."/$ref->{'Database'}.sql"); system("/usr/bin/bzip2 -9 ".$path."/$ref->{'Database'}.sql"); } $sth->finish(); $dbh->disconnect(); ----------------------------------------------------------------------- backup-db.sh you can send script notification using: #!/usr/bin/env sh ( echo "To: Luis Morales <lmorales@venezuelasite.net>" echo "From: system <root@delahorro.com>" PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/lmorales/bin: export PATH echo "Subject: Respaldo diario de la BD::delahorro.com" echo /home/lmorales/bin/backup-db.pl echo ) 2>&1 | /usr/lib/sendmail -t exit 0 ----------------------------------------------------------------------- and finally add this entry to crontab: 0 1 * * * <path to script>/backup-db.sh &> /dev/null Good luck..! regards, Luis Morales

« previous php.db (#37045) next »