AWS RDS備份binlog

cd /home/mariadb/binlog/
vi rds-binlog-backup.sh
 
此shell會本機目錄的最新的一支變數$logname dump出來
目前會有一個問題 當RDS master重啟後binlog序號重新 要先手動下一次
進RDS看最後一支
show binary logs;

mysqlbinlog --read-from-remote-server --raw --stop-never --host=rdsprod-m.c5xxtbetdepg.ap-northeast-1.rds.amazonaws.com binlogname -uking -pmysqlpass
 
mkdir /home/mariadb/binlog
mkdir /home/mariadb/logtmp
vi /home/mariadb/binlog/rds-binlog-backup.sh
#!/bin/bash

location="/home/mariadb/binlog"
nowlocat=`pwd`
if [ $nowlocat != $location ]; then
        echo "WARING! 此程式必須在"$location"目錄下執行";
        exit;
fi

#ls -r|grep mysql-bin-changelog > loglist.txt
#logname=`sed -n '1p' loglist.txt`
mysql -e "show binary logs;" -uking -pmysqlpass -hrdsprod-m.c5xxtbetdepg.ap-northeast-1.rds.amazonaws.com > loglist.txt
logname=`tail -n 1 loglist.txt | awk -F " " '{print $1}'`

mysqlbinlog --read-from-remote-server --raw --stop-never --host=rdsprod-m.c5xxtbetdepg.ap-northeast-1.rds.amazonaws.com $logname -uking -pmysqlpass
排程每天早上6點重啟加tar binlog
0 6 * * * /root/rds-binlog-restart.sh
 
vi /root/rds-binlog-restart.sh
#!/bin/bash

kill -9 $(ps aux|grep "rds-binlog-backup.sh"|grep -v 'grep'|awk '{print $2}')
kill -9 $(ps aux|grep "mysqlbinlog"|grep -v 'grep'|awk '{print $2}')

cd /home/mariadb/binlog
nohup /home/mariadb/binlog/rds-binlog-backup.sh &
sleep 1
mkdir logtmp
mv ./mysql-bin-changelog.* logtmp/
tar zcf /home/mariadb/rds-binlog.`date +%F`.tar.gz ./logtmp/
rm -rf logtmp
sleep 1
ps aux|grep "rds"|grep -v 'grep'
cd

點閱: 16

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料