mysql 数据备份

#!/bin/bash
bak_path=/alidata1/dbbakup
[ ! -d $bak_path ] && mkdir -p $bak_path

file_name=new_sdwan_$(date +%Y%m%d)
/usr/local/mysql/bin/mysqldump --login-path=local --databases new_sdwan --master-data=2  --single-transaction | gzip >$bak_path/${file_name}.sql.gz

#file_name=sdwan_nt_$(date +%Y%m%d)
#/usr/local/mysql/bin/mysqldump --login-path=local --databases sdwan_nt --master-data=2  --single-transaction | gzip >$bak_path/${file_name}.sql.gz

#/usr/local/mysql/bin/mysqldump --databases dphe_test  -B --master-data=2  --single-transaction | gzip >$bak_path/${file_name}.sql.gz

find $bak_path/ -type f -name "*.sql.gz" -mtime +7 | xargs rm -f

定时任务
0 0 * * * root /bin/bash /alidata1/script/sdwan_v1/mysql_bak.sh  &>/dev/null 2>&1
注:有时候需要修改my.cnf,添加mysqldump相关参数(需要开启bin_log)

 

上一篇:5.tar命令批量压缩文件


下一篇:Java批量写入