Recently I came across a situation that required to create backup of websites maintained by me. The CRAVE wiki and CRAVE site administered by me are not regularly updated so i needed something that would backup the databases monthly. This is when it struck me, that cron could solve my problem. Writing a simple shell script and calling the script via cron solved my problem.
Let the script name be dumpdb.sh. The shell script for it is as follows
#!/bin/sh
db_uname="DBUSER";
db_pass="DBPASSWD";
db_name="DBNAME";
dateVar=$(date +%d%b%Y)
mysqldump -u $db_uname -p$db_pass $db_name > ~/mysql_dbbackup/$db_name-$dateVar.sql
This script will create dump of the database. The naming of the file is done by appending date with the database name, this way a unique name is created for every dump. The only job left now is to call this script every first day of month. This job can be done by adding the following line to crontab
01 10 1 * * /path_to_script/dumpdb.sh
This will run the script at 10.00am every first day of month. Thats all one must do to automate the backing up of their databases.
Let the script name be dumpdb.sh. The shell script for it is as follows
#!/bin/sh
db_uname="DBUSER";
db_pass="DBPASSWD";
db_name="DBNAME";
dateVar=$(date +%d%b%Y)
mysqldump -u $db_uname -p$db_pass $db_name > ~/mysql_dbbackup/$db_name-$dateVar.sql
This script will create dump of the database. The naming of the file is done by appending date with the database name, this way a unique name is created for every dump. The only job left now is to call this script every first day of month. This job can be done by adding the following line to crontab
01 10 1 * * /path_to_script/dumpdb.sh
This will run the script at 10.00am every first day of month. Thats all one must do to automate the backing up of their databases.
Nice job :)
ReplyDeleteIt would also make sense to backup the file system, since images and other binary files are not stored in the MediaWiki/Joomla database.
Thanks
ReplyDeleteI forgot about it. Will work on that part too.