How To Automatically Backup Your MySQL Databases

It is very important to regularly backup your important MySQL databases. We have found a script that will allow you to easily backup your MySQL databases.

$email_backup                = 'yes';
$admin_email_to              = "you\@yourdomain.com";
$admin_email_from            = "webmaster\@yourdomain.com";
Enter the databases you would like to backup, separated by spaces.
@selected_databases  = qw[cpanelid_dbname1 cpnaleid_dbname2];
Set process all databases to no.
$process_all_databases       = 'no';
Set the password location to this_file
$password_location           = 'this_file';
Now lets setup your database login information. The username and password are the same as when you created your MySQL database and users from cpanel.
$user                        = 'mysqldb_id';
$password                    = 'mysqldb_password';

You will also need to setup the directory to save the backups to
$mysql_backup_dir            = '/home/cpanelid/mysql_backups';
This is the minimum that you will need to configure, if you have an ftp account on another server, you can also have the program automatically ftp the backup to that account. The next step is to create the backup directory.
mkdir mysql_backups
Now test the script and make sure it works.
If you get an error, feel free to email support@railsplayground.com for help.


if it helps anyone, it’s really a lot easier than all this:

ssh user@domain.com “mysqldump—user=user—password=password example_database” > /Users/user/backups/my_website_db.sql

that gets your database in one line from your own computer. just put it on cron on your computer. if you wanted to make copies on your webserver itself, just drop the ssh part and the double quotes. in either case, set the output path you want and put in your username and password and database name.

edit: some spaces appear to have been dropped by the wiki software. put spaces between each part.


Can someone please write about how to restore a database using the .txt archive provided by this script? Thanks.


To restore an entire db from this .txt archive… I’m doing this on a local machine and using CocoaMysql to import into my railsplayground account.

I’m no expert, but I hope this helps.

The script home page gives the following command for restoring, calling it better than the option above. See http://worldcommunity.com/opensource/utilities/mysql_backup.html for details.

find . -name "*.txt" -print | xargs -t --replace cat {} | mysql test

———- Online References