Backing up your mysql on linux box per each database


#!/bin/bash
MUSER="root"
MPASS="password"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BAK="/mnt/backupdir"
GZIP="$(which gzip)"
NOW=$(date +"%d_%m_%Y")
for i in `find $BAK -ctime +22`; do rm $i; done
[ ! -d $BAK ] && mkdir -p $BAK
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
 FILE=$BAK/$db.$NOW.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done


it deletes every 22 days old backups if you want to change life-time,
you can change the value of ctime in the followed line: for i in `find $BAK -ctime +22`; do rm $i; done
  • 0
  • February 15, 2010, 12:39pm
  • EvgenyM

Comments (0)

RSS Collapse / Expand

Only registered and authorized users can leave comments. Login or Register