logo
关于我们

技术分享

技术分享 数据库备份周日全量+日增量备份脚本

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

2021-06-07


#!/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 -h127.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 -h127.0.0.1 -P${DB_PORT} -uroot -e"grant replication slave on *.* to replica@'10.37.53.%' identified by '密码'"
/usr/bin/mysql -h127.0.0.1 -P${DB_PORT} -uroot -e"grant all on *.* to mha_user@'10.37.53.%' identified by '密码'"
/usr/bin/mysql -h127.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


云祺备份软件,云祺容灾备份系统,虚拟机备份,数据库备份,文件备份,实时备份,勒索软件,美国,图书馆
  • 标签:
  • 行业资讯

您可能感兴趣的新闻 换一批

现在下载,可享30天免费试用

立即下载