原创

mysql备份脚本

一、用 mysql_config_editor 生成登录密钥

mysql_config_editor set --login-path=mydb --host=127.0.0.1 --user=root --password

详细说明:用 mysql_config_editor 生成登录密钥

二、备份脚本

#/bin/bash
DAYTIME=$(date +%Y%m%d)
BACKUPDIR="/mysqlbackup"
BACKUPLOG="/mysqlbackup/logbackup.log"
BACKUPFILE="$BACKUPDIR/$DAYTIME.sql"

echo $(date +%Y-%m-%d" "%H:%M:%S) "-----------------start-----------------" >>$BACKUPLOG
`mysqldump --login-path=mydb -A --master-data=2 --single-transaction --max_allowed_packet=64M --set-gtid-purged=off  >$BACKUPFILE` >>$BACKUPLOG  2>&1
if [ $? -eq 0 ]
        then
        echo "backup success!" >>$BACKUPLOG
        echo "backupfile:$BACKUPFILE" >>$BACKUPLOG
        if [ -a $BACKUPFILE ]
                then
                echo "clear 7 days ago" >>$BACKUPLOG
                echo "clear file name:" >>$BACKUPLOG
                echo $(find $BACKUPDIR -mtime +6 -name "*.sql") >>$BACKUPLOG
                find $BACKUPDIR -mtime +6 -name "*.sql" -exec rm -f {} \;
        fi
else
        echo "backup fail!" >>$BACKUPLOG
fi
echo $(date +%Y-%m-%d" "%H:%M:%S) "-----------------e n d-----------------" >>$BACKUPLOG
正文到此结束
温馨提示:
本文最后更新于 2024年05月01日,已超过 161 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我
本文目录