Re: MySQL backup software

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx>"
echo "From: system <root@xxxxxxxxxxxxx>"
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

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux