View Full Version : How to setup Cron to backup MySQL DBs
Verbal
2005-07-28, 08:25 PM
Can someone explain or link a tuorial on how to backup all my MySQL databases with a Cron? I'd like to back them up like Mon, Wed, Fri and have a copy emailed to me. I think this is just a matter of automating mysqldump on all the db's, but I haven't set this up before. Thanks. :)
crontab entry:
0 1 * * 1,3,5 /usr/bin/mysqldump -q -u username -p"password" databasename > /tmp/file.sql;gzip /tmp/file.sql;/var/www/email.pl
email.pl
#!/usr/bin/perl -w
use MIME::Lite;
$msg = MIME::Lite->new(
From => 'user@domain.com',
To => 'user@domain.com',
Subject => 'mysql backup',
Type => 'text/plain',
Data => "backups attached");
$msg->attach(Type=>'application/x-tar',
Path =>"/tmp/file.sql.gz",
Filename =>"file.sql.gz");
$msg->send;
Verbal
2005-07-30, 12:28 AM
Thanks for the info cd34! Time to start automating these things. :)
I did it about the same way that cd34 posted but since I learned ho to do rsync I stopped having things mailed to me and just do the database dump to my server's drive. I then have my laptop's cron do rsync each night and keep a mirror of my server on my laptop which includes the database dumps.
I setup seven different dumps each week so that I have seven versions of my databases.
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.