Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   How to setup Cron to backup MySQL DBs (http://www.greenguysboard.com/board/showthread.php?t=22459)

Verbal 2005-07-28 07:25 PM

How to setup Cron to backup MySQL DBs
 
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. :)

cd34 2005-07-28 08:17 PM

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
Code:

#!/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-29 11:28 PM

Thanks for the info cd34! Time to start automating these things. :)

Cleo 2005-07-30 12:59 AM

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.


All times are GMT -4. The time now is 09:35 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc