mysqldump备份脚本

#! /bin/bash

STORE_NAME=`date +%m%d`
STORE_DIR='/home/backup/mysql/'
exec 1>/var/log/mysqlbak.log 2>&1

echo mysqlbak begin at `date`
[ ! -d $STORE_DIR ] && mkdir -p $STORE_DIR

/usr/local/mysql/bin/mysqldump  -uroot -p'password' databasename > $STORE_DIR/mysql-$STORE_NAME.sql
gzip $STORE_DIR/mysql-$STORE_NAME.sql

find $STORE_DIR  -mtime +7 -name '*.sql.gz' |xargs rm -f

echo mysqlbak finish at `date`

添加新评论 »