Skip to main content

Automating MySQL DB backup

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.

Comments

  1. Nice job :)

    It would also make sense to backup the file system, since images and other binary files are not stored in the MediaWiki/Joomla database.

    ReplyDelete
  2. Thanks

    I forgot about it. Will work on that part too.

    ReplyDelete

Post a Comment

Popular posts from this blog

Uninstalling problem with Vmware

Vmware is good software to use though it has some limitations mainly as it not an OSS. Secondly there is this uninstallation problem, say you did not install properly or you wish to uninstall it. Here uninstalling vmware compared to other software on Ubuntu is pain especially if you dont know the specific procedure.I wanted to reinstall vmware, that's when i came across this problem. I had given up the hope, when i read on forums that others too have faced this problems. The usual method of uninstalling any software is $ sudo apt-get remove [package-name] For uninstalling vmware-server the following steps need to be followed $ sudo rm -r /etc/vmware $ sudo apt-get remove --purge vmware-server This should solve the problem usually, if it doesn't then you need to specify your problem on one of the forums.

Smart Board Driver for Linux

Well it seems the search for driver at crave lab is over, we had doubts whether Smart Board Driver for Linux was available. The good thing is that it is available and supported well by Smart Board for different platforms. We intend to try it out today, hope things work out of box. If it works we will try Beryl on it too.

Open Source Software Week @ DBIT

DUCS & CRAVE are organizing a week long event called Open Source Software Week at DBIT . The OSS week will be conducted in 3 rd week of October i.e from 13 th - 18 th of October. The aim of the program is to introduce the students & staff to Open Source technology. This will also serve as a platform for introducing the freshers to Open Source thereby getting new CRAVE members (hardly any left). The OSS schedule is for the week is as follows - Linux Workshop (Architecture, Installation, ..) Animation (Blender) Graphic Designing (Inkscape, GIMP) Programming & Web Development (Editors, Apache, MySQL, ..) LaTeX Workshop Open Office Suite Gaming (Openarena, Torcs, UrbanTerror, ..) The Workshops will be conducted by Royston, Maddy & me. As of now the poster for the event has been completed mostly. The registration for the event will begin from 3 rd October. That's all for now, got to do some preparation for the event.