Wednesday, November 19, 2008

My sql backup script

#!/bin/bash
# Bcakup of Cyclone MySQL one/all databases for 7 days
# Umakanta Samantaray
# Date 10th Sep 2008
#
#
#

DBBACKUPDIR=/home/backups/mysql
DTSTAMP=`date "+%Y%m%d@%H%M"`
DBNAME=forecast_tracker_prod

# Only one database backup ie "forecast_tracker_prod"
if [ -d $DBBACKUPDIR ] ; then
mysqldump -u mysqlbackupadmin -pmysql@cyclone -h localhost --opt -B $DBNAME \
> $DBBACKUPDIR/cyclone.mysql.${DBNAME}.${DTSTAMP}.sql
bzip2 -sz $DBBACKUPDIR/cyclone.mysql.${DBNAME}.${DTSTAMP}.sql
find $DBBACKUPDIR -type f -name '*.sql.*' -mtime +7 -exec rm {} \;

else
echo $DBBACKUPDIR does not exist
exit 1
fi

# All databases in a single file.
# mysqldump -u mysqlbackupadmin -pmysql@cyclone -h localhost --opt --all-databases > $DBBACKUPDIR/cyclone.mysql.alldatabases.$DTSTAMP.sql

No comments: