您好,登錄后才能下訂單哦!
相信很多做運維的小伙伴都會用到mysql數(shù)據(jù)庫,以下提供一個腳本與諸君分享。
#!/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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。