mysql自动备份shell脚本[MySQL防范]
本文“mysql自动备份shell脚本[MySQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
#!/bin/bash
bak_path=/data/bak_path
mysql_bk_dir=$bak_path/mysql_bk_dir
log_file=$backup_path/backuplog
password=123456
for i in $(mysql -p$password -e "show databases\G" |grep Database | awk '{print $2}')
do
new_file="$mysql_bk_dir"/$i$(date +%Y%m%d).tar.gz
dump_file="$mysql_bk_dir"/$i$(date +%Y%m%d).sql
old_file="$mysql_bk_dir"/$i$(date +%Y$m%d).tar.gz
echo "------------------------------------------------------------" >> $log_file
echo $(date +"%Y-%m-%d %H:%M:%S") >> $log_file
echo "------------------------------------------------------------" >> $log_file
if [ -f $old_file ]; then
rm -rf $old_file >> $log_file 2>&1;
echo "[$old_file] Delete Old File Success!" >> $log_file
else
echo "[$old_file] No Old Backup File!" >> $log_file
fi
if [ -f $new_file ]; then
echo "[$new_file] The backup file is exist, can't backup!" >> $log_file;
else
cd $mysql_bk_dir
/usr/local/mysql/bin/mysqldump --opt $i -p$password > $dump_file
tar zcf $new_file $dump_file >> $log_file 2>&1
echo "[$new_file] Backup success!" >> $log_file
rm -rf $dump_file
fi
sleep 15
done
以上是“mysql自动备份shell脚本[MySQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |