相信很多做运维的小伙伴都会用到Mysql数据库,以下提供一个脚本与诸君分享。#!/bin/bashSCRIPT_DIR=$(dirname $0)BACKUP_DIR="/data1/mysqlb
相信很多做运维的小伙伴都会用到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
--结束END--
本文标题: 数据库备份周日全量+日增量备份脚本
本文链接: https://www.lsjlt.com/news/41395.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0