您好,登錄后才能下訂單哦!
相關關鍵詞:
策略規劃,恢復演練,還原與恢復
恢復點目標(PRO):容忍丟失多少數據
恢復時間目標(RTO):需要多久將數據恢復
備份理由:災難恢復,錯誤修改,審計,測試
##查看幫助
mysqldump --help
##備份某個表
mysqldump -uroot -h227.0.0.1 -p'password' sakila test > sakila_test.sql
##備份某個數據庫
mysqldump -uroot -p'password' -h227.0.0.1 --single-transaction --triggers --routines --databases sakila > sakila.sql
##備份所有數據庫
mysqldump --single-transaction --quick --flush-logs --master-data=2 --all-databases --triggers --routines --events --set-gtid-purged=off > backup.sql
##查看當前二進制日志
mysql> show master status;
##備份時切換日志,并記錄后續日志,如新日志從mysql-bin.000007 開始
##讀取增量的二進制日志
mysqlbinlog --skip-gtids mysql-bin.000007 > bin7.sql
mysqlbinlog --skip-gtids mysql-bin.000008 > bin8.sql
##完全恢復
mysql> source backup.sql;
mysql> source bin7.sql;
mysql> source bin8.sql;
shell> mysqlbinlog --stop-date="2019-09-11 9:59:59" mysql-bin.000007 > bin7_pos1.sql
shell> mysqlbinlog --start-date="2019-09-11 10:01:01" mysql-bin.000007 > bin7_pos2.sql
shell> mysqlbinlog --skip-gtids mysql-bin.000008 > bin8.sql
mysql> source backup.sql;
mysql> source bin7_pos1.sql;
mysql> source bin7_pos2.sql;
mysql> source bin8.sql;
shell>mysqlbinlog --start-date="2019-09-11 9:59:59" --stop-date="2019-09-11 10:01:01" mysql-bin.000007 >bin7_pos.sql
#找到位置號,如3601 和 3609
shell> mysqlbinlog --stop-position="3601" mysql-bin.000007 > bin7_pos1.sql
shell> mysqlbinlog --start-position="3609" mysql-bin.000007 > bin7_pos2.sql
mysql> source backup.sql;
mysql> source bin7_pos1.sql;
mysql> source bin7_pos2.sql;
mysql> source bin8.sql;
```shell 略
## 5.2 物理備份
### 5.2.1 Xtrabackup安裝
1.添加源
```shell
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
##檢查
yum list|grep percona-xtrabackup-24.x86_64
2.安裝
##缺少依賴包libev.so.4的處理
rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm
##安裝
rpm -ivh percona-xtrabackup-80-8.0.7-1.el7.x86_64.rpm
##創建備份用戶
create user 'backup'@'%' identified by 'Bk_123456';
grant reload,lock tables,replication client,create tablespace,process,super on *.* to 'backup'@'%';
##普通備份
innobackupex --default-file=/data/mysql/3306/my3306.cnf --host=192.168.56.16 --user=backup --password='Bk_123456' --datadir=/data/mysql/3306/data --port=3306 --slave-info --no-timestamp /home/mysql/backup/dbfull_3306_`date '+%Y%m%d_%H%M'`
##流式壓縮備份
innobackupex --default-file=/data/mysql/3306/my3306.cnf --host=192.168.56.16 --user=backup --password='Bk_123456' --datadir=/data/mysql/3306/data --port=3306 --no-timestamp --stream=xbstream -> /home/mysql/backup/backup.xbstream.`date '+%Y%m%d_%H%M'`
##加密備份
innobackupex --default-file=/data/mysql/3306/my3306.cnf --host=192.168.56.16 --user=backup --password='Bk_123456' --datadir=/data/mysql/3306/data --port=3306 --encrypt=AES256 --encrypt-threads=10 --encrypt-key=111111111111111111111111 --encrypt-chunk-size 512 --no-timestamp --stream=xbstream -> /home/mysql/backup/backup.xbstream.encrypt.`date '+%Y%m%d_%H%M'`
##普通增量
innobackupex --defaults-file=/data/mysql/3306/my3306.cnf --host=192.168.56.16 --user=root --password='password' --datadir=/data/mysql/3306/data --incremental-basedir=/data/mysql/backup/2019-09-11_16-47-59 --incremental /data/mysql/backup/increment
##流式加密增量
innobackupex --defaults-file=/data/mysql/3306/my3306.cnf --host=192.168.56.16 --user=root --password='password' --datadir=/data/mysql/3306/data --incremental-basedir=/data/mysql/backup/2019-09-11_16-47-59 --incremental --compress --compress-threads=10 --encrypt=AES256 --encrypt-threads=10 --encrypt-key=111111111111111111111111 --stream=xbstream ./ > /data/mysql/backup/increment/increment.stream
如果是第二次增量,—incremental-basedir= 上次增量的目錄
##流式解壓
mkdir /home/temp
xbstream -x < /data/mysql/backup/backup.xbstream -C /home/temp
innobackupex --decompress --decrypt=AES256 --encrypt-key=1111111111111111111111111 /home/temp
innobackupex --copy-back --defaults-file=/data/mysql/3306/my3306.cnf /home/temp
##應用redo
innobackupex --host=192.168.56.16 --user=backup --password='Bk_123456' --apploy-log /home/mysql/backup/2019-09-12_10-18-57
##恢復全備(關閉數據庫,清空數據目錄)
innobackupex --default-file=/data/mysql/3306/my3306.cnf --datadir=/data/mysql/3306/data --copy-back /home/mysql/backup/2019-09-12_10-18-57
chown -R mysql:mysql /data/mysql
##
innobackupex --host=192.168.56.16 --user=backup --password='Bk_123456' --apply-log --redo-only /home/mysql/backup/2019-09-12_10-18-57
##
innobackupex --host=192.168.56.16 --user=backup --password='Bk_123456' --apply-log --redo-only /home/mysql/backup/2019-09-12_10-18-57 --incremental-dir=/data/mysql/backup/increment/2019-09-12_09-11-23
##
innobackup --host=192.168.56.16 --user=backup --password='Bk_123456' --apply-log /home/mysql/backup/2019-09-12_10-18-57 --incremental-dir=/data/mysql/backup/increment/2019-09-13_09-11-50
##恢復全備(關閉數據庫,清空數據目錄)
innobackupex --default-file=/data/mysql/3306/my3306.cnf --datadir=/data/mysql/3306/data --copy-back /home/mysql/backup/2019-09-12_10-18-57
chown -R mysql:mysql /data/mysql
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。