/opt/shells/bak_db09.sh

#!/bin/bash
datastr=/nfs_nas/bakup/db09
DBHost="172.16.0.2"
DBUSER="test"
password="123456"
port="3306"
backupstr=mysqlbak(date +%Y%m%d%H%M)
db_not_bak="information_schema performance_schema mysql test_xxl"
db_not_bak_except="test"

echo "这些表不备份"db_not_bak
cd datastr
mkdirbackupstr
cd backupstr
totalDB=(mysql -N -h DBHost -uDBUSER -ppassword -Pport <<EOF
show databases;
EOF
)
###IFS
OLD_IFS="IFS"
IFS=" "
arr=(totalDB)
IFS="OLD_IFS"
for db in{arr[@]}
do
        if [[ db_not_bak =~db ]] && [[ ! db_not_bak_except =~db ]]
then
    echo "db" "不备份" 
else
    echo  "db" "开始备份..."
    #mysqldump  -h DBHost  -uroot  -ppassword   -Pport  --default-character-set=utf8 --single-transaction --master-data=2 -R -E -dtdb   >db.sql
    mysqldump  -hDBHost  -uDBUSER  -ppassword   -Pport  --default-character-set=utf8 --single-transactiondb   >db.sql
    echo  "db" "备份完成"
fi
done

# 压缩为tgz
cd datastr
tar zcvfbackupstr".tgz" backupstr
if [ "0" -eq? ];then
    rm -rf $backupstr
fi

crontab

#echo "00 */3 * * * /opt/shells/bak_db09.sh" >> /var/spool/cron/crontabs/root
echo "00 */3 * * * /opt/shells/bak_db09.sh" >> /var/spool/cron/root

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code