服务器上的处理脚本记录:
[root@mysql01 test]# crontab -l
0 2 * * * /bin/sh /script/sqlbackup.sh >/dev/null 2>&1
[root@mysql01 test]# cd /script/
[root@mysql01 script]# cat sqlbackup.sh
#!/bin/sh
#MySQL library database backup
. /etc/init.d/functions
soure /etc/profile
Prog_path="/application/mysql/bin"
Mysql_user="root"
Mysql_pwd="Hn11cgo111@2016"
Socket="/data/mysql.sock"
Backup_dir=/backup
Time=$(date "+%F")
[ -d ${Backup_dir} ] || mkdir -p ${Backup_dir}
mkdir ${Backup_dir}/${Time} -p
a=(` ${Prog_path}/mysql -u$Mysql_user -p$Mysql_pwd -S $Socket -e 'show databases;'|egrep -v "information_schema|bate_bbc|demo_bbc|demo_oms|mysql|performance_schema|zentao" ` ) ------------把不用备份的排除
for db in ${a[@]}
do
b=(`${Prog_path}/mysql -u$Mysql_user -p$Mysql_pwd -S $Socket -e "show tables from $db;"`)
for table in ${b[@]}
do
[ -d ${Backup_dir}/${Time}/${db} ]|| mkdir -p ${Backup_dir}/${Time}/${db}
${Prog_path}/mysqldump -u$Mysql_user -p$Mysql_pwd -S $Socket -x -E $db $table |gzip>${Backup_dir}/${Time}/${db}/${table}_${Time}.sql.gz
#${Prog_path}/mysqldump -u$Mysql_user -p$Mysql_pwd -S $Socket -x -E -B $db |gzip>${Backup_dir}/${db}_$(date +%F).sql.gz
done
done
[root@mysql01 script]#