shell - mysql逻辑备份

2022-06-05
#!/bin/bash
delete_day=7
BasePath=/volume1/backup/mysql
Today=$(date "+%Y%m%d")
Yesterday=$(date -d yesterday +"%Y%m%d")
mkdir -p $BasePath/$Today

for host in $(kubectl -n middleware get svc --show-labels  | grep ^mysql-| awk -F 'domain=' '{print $NF}')
do
        mkdir -p $BasePath/$Today/$host
        for database in `mysql -h${host} -uroot -p'xx' -Ne "show databases;"| grep -v "yqn_scheduler\|information_schema\|mysql\|performance_schema\|sys"`
        do
                mysqldump -h${host} -uroot -p'xx' $database --set-gtid-purged=OFF > $BasePath/$Today/$host/${database}.sql
                if [ $? -eq 0 ];then
                        echo "`date +'%Y-%m-%d %H:%M:%S'` $host $database backup success!"
                else
                        echo "`date +'%Y-%m-%d %H:%M:%S'` $host $database backup failed!"
                fi
        done
done

if [[ $? -eq 0 ]];then
    find ${BasePath} -maxdepth 1 -mindepth 1 -type d -ctime +${delete_day}  | xargs rm -rf
else
    echo "send dingding"
    exit 1
fi

标题:shell - mysql逻辑备份
地址:https://blog.njqhome.com:8443/articles/2022/06/05/1654401864592.html