Difference between revisions of "Periodic backup of database"
From Notes_Wiki
m |
m |
||
Line 1: | Line 1: | ||
<yambe:breadcrumb>Useful_bash_shell_scripts|Useful bash shell scripts</yambe:breadcrumb> | |||
=Periodic backup of database= | =Periodic backup of database= | ||
Revision as of 10:56, 18 January 2013
<yambe:breadcrumb>Useful_bash_shell_scripts|Useful bash shell scripts</yambe:breadcrumb>
Periodic backup of database
Periodic backup of database can be taken by using scripts like:
#!/bin/sh BACKUP_DIR=<backup_dir>/$(date +%Y-%m-%d) mkdir -p $BACKUP_DIR mysqldump -u <user-name> -p<password> <database-name> > $BACKUP_DIR/`date +%Y-%m-%d\:%H-%M-%S`.sql exit 0
Replace: <backup_dir>, <user-name>, <password> and <database-name> appropriately.
This script can be put in '/etc/cron.hourly' or '/etc/cron.daily' or '/etc/cron.weekly' or '/etc/cron.monthly' based on frequency of backups desired.
- Make sure to do 'chmod +x' on script so that it is executable.
- If you do not want to be bothered by cron output of above script then add '>/dev/null 2>&1' at end of all commands