Here are some simple steps for data backup in My-Sql:-
First,you have to create a simple script called db backup to backup and compress your database:
#!/usr/bin/bash
mysqldump -uusername -ppassword yourdbname > yourdbname.sql
tar -zcvf sqldata.tgz *.sql
perl /home/emaxx/sqlbk/dbmail.cgi
If you have more than one databases you can repeat line 2 as many times as necessary. Line 3 will simply gzip any .sql files in the directory. You can find full documentation on the mysqldump command on the MySQL.com wesbite.
after thatyou have to create another script called dbmail.cgi to email your gzipped mysqldump results to an address of your choice. In order for this to work, you must have MIME::Lite installed and available to you. Ask your hosting provider to enable it if it isn’t already. Now on to the email script:
#!/usr/bin/perl -w
use MIME::Lite;
$msg = MIME::Lite->new(
From => 'any@address.com',
To => 'my@address.com',
Subject => 'your db backup',
Type => 'text/plain',
Data => "Attached you will find your database backups for today.");
$msg->attach(Type=>'application/x-tar',
Path =>"sqlbackup.tgz",
Filename =>"sqlbackup.tgz");
$msg->send;
Now replace the From and To addresses in lines 6 and 7 and you’re set. If you’d like you could always send to multiple addresses or customize the text in your message.
Now that these two scripts are complete and in place, verify that they work by running the dbbackup script from the shell. If you don’t have shell access to your account, either get it, or skip this step and read on.
Finally, you setup a cron job to run the dbbackup script on a schedule. I
1. 0 3 * * * /full/path/to/dbbackup
That should about do it.
Now you are ready to recieve every day with an email containing your latest database.
|