Wednesday, December 27, 2006

Automated database backups via cron

Here is a quick and dirty script to do automated backups of a mysql database. If you want the script to be executed hourly (as is in my case), place it in your /etc/cron.hourly directory. In my case, I dump the backups onto /local/backups directory which happens to be mirrored via raid1.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh

x=`date +%d-%H`
abrcimsfile1="v2edclite${x}"
abrcimsfile2="abrcimsv1${x}"

mysqldump -u root -p v2edclite_v1 > /local/backups/$abrcimsfile1
mysqldump -u root -p abrcims_v1 > /local/backups/$abrcimsfile2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 comments:

About Me

My Photo
Princeton, New Jersey, United States
I am a programmer by day and a network admin by night. While my primary specialty is developing secure database driven web applications for FDA regulated industries such as Pharmaceuticals, I am also a network administrator managing both windows and Linux networks. I am very passionate about open source technologies and use them in my daily work life as often as I can.