您好,登錄后才能下訂單哦!
相關(guān)關(guān)鍵詞:
策略規(guī)劃,恢復(fù)演練,還原與恢復(fù)
恢復(fù)點(diǎn)目標(biāo)(PRO):容忍丟失多少數(shù)據(jù)
恢復(fù)時(shí)間目標(biāo)(RTO):需要多久將數(shù)據(jù)恢復(fù)
備份理由:災(zāi)難恢復(fù),錯(cuò)誤修改,審計(jì),測(cè)試
##查看幫助
mysqldump --help
##備份某個(gè)表
mysqldump -uroot -h227.0.0.1 -p'password' sakila test > sakila_test.sql
##備份某個(gè)數(shù)據(jù)庫(kù)
mysqldump -uroot -p'password' -h227.0.0.1 --single-transaction --triggers --routines --databases sakila > sakila.sql
##備份所有數(shù)據(jù)庫(kù)
mysqldump --single-transaction --quick --flush-logs --master-data=2 --all-databases --triggers --routines --events --set-gtid-purged=off > backup.sql
##查看當(dāng)前二進(jìn)制日志
mysql> show master status;
##備份時(shí)切換日志,并記錄后續(xù)日志,如新日志從mysql-bin.000007 開始
##讀取增量的二進(jìn)制日志
mysqlbinlog --skip-gtids mysql-bin.000007 > bin7.sql
mysqlbinlog --skip-gtids mysql-bin.000008 > bin8.sql
##完全恢復(fù)
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
#找到位置號(hào),如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
##創(chuàng)建備份用戶
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
##應(yīng)用redo
innobackupex --host=192.168.56.16 --user=backup --password='Bk_123456' --apploy-log /home/mysql/backup/2019-09-12_10-18-57
##恢復(fù)全備(關(guān)閉數(shù)據(jù)庫(kù),清空數(shù)據(jù)目錄)
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
##恢復(fù)全備(關(guān)閉數(shù)據(jù)庫(kù),清空數(shù)據(jù)目錄)
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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。