温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

数据库备份周日全量+日增量备份脚本

发布时间:2020-07-13 22:44:10 来源:网络 阅读:615 作者:蜗牛的嘲讽 栏目:数据库

相信很多做运维的小伙伴都会用到mysql数据库,以下提供一个脚本与诸君分享。


#!/bin/bash
SCRIPT_DIR=$(dirname $0)
BACKUP_DIR="/data1/mysqlbackup"
BACKUP_DAYS=480
rm -rf ${BACKUP_DIR}/*
DB_IP=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" |head -1`
BACKUP_TYPE='xtra_full'
for i in `ps -ef |grep port= |grep -v grep|cut -d "=" -f 10`
do 
DB_PORT=$i
NEW_DIR="/data1/mysqlbackup/${DB_PORT}"
if [ -e "$NEW_DIR" ]
 then
    echo  "$NEW_DIR was created"
else
    mkdir $NEW_DIR
fi
BACKUP_TODAY="/data1/mysqlbackup/${DB_PORT}/${DB_IP}_`date +%Y%m%d%H%M`"

#find ${BACKUP_DIR} -mindepth 2 -type d -cmin +${BACKUP_DAYS} -exec rm -rf {} \;

/usr/bin/mysql -h227.0.0.1 -P${DB_PORT} -uroot -e"GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'mysqlbackup'@127.0.0.1 IDENTIFIED BY 'abc123'"
/usr/bin/mysql -h227.0.0.1 -P${DB_PORT} -uroot -e"grant replication slave on *.* to replica@'10.37.53.%' identified by '密码'"
/usr/bin/mysql -h227.0.0.1 -P${DB_PORT} -uroot -e"grant all on *.* to mha_user@'10.37.53.%' identified by '密码'"
/usr/bin/mysql -h227.0.0.1 -P${DB_PORT} -uroot -e"grant all on *.* to zabbix_monitor@'127.0.0.1' identified by '密码'"

innobackupex --user=mysqlbackup --password=abc123 --host=127.0.0.1  --port=${DB_PORT}  --defaults-file=/etc/mysql/my${DB_PORT}.cnf --no-timestamp   $BACKUP_TODAY 2>/var/log/mysql${DB_PORT}.log


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI