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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

No comments:

About Me

My photo
Princeton, New Jersey, United States
I am an Information Technology Analyst with extensive background in the Clinical Industry that includes working for CROs, Pharmaceutical and Medical Diagnostic companies.