#!/bin/sh
#backup mysql database
#一、如果没有密码用
#mysqldump -q -a -c -u root  --opt $DBName | gzip > $BackupPath/$DBName.$rq.sql.gz
#二、定时任务 每天凌晨三点
#vi /etc/crontab
#01 3 * * * root /usr/sbin/mysql.sh
#三、重新启动crond
#/etc/rc.d/init.d/crond restart
#:set ff 或 :set fileformat
#:set ff=unix 或 :set fileformat=unix

DBName=test
DBUser=root
DBPasswd=
BackupPath=/data/backup/mysql

#delete file 删除7天前的备份
find $BackupPath -type f -mtime +7 -exec rm {} \;

rq=`date +%Y%m%d%H%M`
#backup each database
mysqldump -q -a -c -u root -p$DBPasswd --opt $DBName | gzip > $BackupPath/$DBName.$rq.sql.gz