Pages

Tuesday, June 26, 2012

Mysql Database Backup script

Create a file called database_backup.sh and also an empty directory called mysql_backup.

The database_backup.sh script should have the following info :


#!/bin/sh 
date=`date '+%m-%d-%y'`


PATH="~/mysql_backup/database_name.$date"


mysqldump -u database_username -pdatabase_password database_name > $PATH



Run the script that performs the backup job.

Using Cron  :

Set this script up to run every night, etc. as a cron job. It will save an sql dump of your database every night in the mysql_backup.
e.g

* 23 * * * your_userid /path/to/backup/script

No comments:

Post a Comment