1. 程式人生 > >xtrabackup 備份和恢復

xtrabackup 備份和恢復

                  該文章接上一篇文章:

核心方面:

$ cat /etc/centos-release
  CentOS Linux release 7.4.1708 (Core)
$ uname -r
  3.10.0-693.el7.x86_64

下載安裝xtrabackup:
$ wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.12/binary/redhat/7/x86_64/Percona-XtraBackup-2.4.12-r170eb8c-el7-x86_64-bundle.tar
$ tar -xf Percona-XtraBackup-2.4.12-r170eb8c-el7-x86_64-bundle.tar
$ yum -y install percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
$ which xtrabackup
  /usr/bin/xtrabackup
$ innobackupex -v
  xtrabackup: recognized server arguments: --innodb_buffer_pool_size=1024M --datadir=/data/mysql/data --server-id=1


建立測試資料:
mysql> mysql -uroot -p
mysql> create database opop charset='utf8mb4';
mysql> use opop;
mysql> create table user(id int unsigned primary key auto_increment,name varchar(30));
mysql> show tables;
mysql> insert into user(name) values('jack'),('tom'),('lily'),('lucy');
mysql> select * from user;
mysql> commit;
mysql> select * from user;


Xtrabackup全量備份與恢復
$ innobackupex --defaults-file=/etc/my.cnf --user=sstuser --password="123456" --backup .        #最後有個點,是當前目錄

xtrabackup: recognized server arguments: --innodb_buffer_pool_size=1024M --datadir=/data/mysql/data --server-id=1
xtrabackup: recognized client arguments: --innodb_buffer_pool_size=1024M --datadir=/data/mysql/data --server-id=1 --backup=1
181025 08:27:43 innobackupex: Starting the backup operation

IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".

181025 08:27:43 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'sstuser' (using password: YES).
181025 08:27:43 version_check Connected to MySQL server
181025 08:27:43 version_check Executing a version check against the server...
181025 08:27:43 version_check Done.
181025 08:27:43 Connecting to MySQL server host: localhost, user: sstuser, password: set, port: not set, socket: not set
Using server version 5.7.23-23-57
innobackupex version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /data/mysql/data
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
InnoDB: Number of pools: 1
181025 08:27:43 >> log scanned up to (2605686)
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID 2 for mysql/plugin, old maximum was 0
181025 08:27:44 [01] Copying ./ibdata1 to /root/2018-10-25_08-27-43/ibdata1
181025 08:27:44 [01] ...done
....
....

181025 08:27:46 Executing LOCK TABLES FOR BACKUP...      #翻譯:執行鎖定表以進行備份
181025 08:27:46 Starting to backup non-InnoDB tables and files
181025 08:27:46 [01] Copying ./mysql/db.opt to /root/2018-10-25_08-27-43/mysql/db.opt
181025 08:27:46 [01] ...done
181025 08:27:46 [01] Copying ./mysql/db.frm to /root/2018-10-25_08-27-43/mysql/db.frm
181025 08:27:46 [01] ...done
....
....

181025 08:27:47 [01] Copying ./opop/user.frm to /root/2018-10-25_08-27-43/opop/user.frm
181025 08:27:47 [01] ...done
181025 08:27:47 Finished backing up non-InnoDB tables and files
181025 08:27:47 Executing LOCK BINLOG FOR BACKUP...      #執行鎖定二進位制檔案開始備份
181025 08:27:47 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...    #執行flush no_write_to_binlog引擎日誌
xtrabackup: The latest check point (for incremental): '2605677'
xtrabackup: Stopping log copying thread.                #停止日誌複製執行緒。
.181025 08:27:47 >> log scanned up to (2605686) #日誌掃描到(2605686)

181025 08:27:47 Executing UNLOCK BINLOG            #執行解鎖binlog
181025 08:27:47 Executing UNLOCK TABLES            #執行解鎖表
181025 08:27:47 All tables unlocked                  #所有表解鎖
181025 08:27:47 [00] Copying ib_buffer_pool to /root/2018-10-25_08-27-43/ib_buffer_pool
181025 08:27:47 [00] ...done
181025 08:27:47 Backup created in directory '/root/2018-10-25_08-27-43/'        #在/root/2018-10-25_08-27-43/目錄中建立備份
181025 08:27:47 [00] Writing /root/2018-10-25_08-27-43/backup-my.cnf
181025 08:27:47 [00] ...done
181025 08:27:47 [00] Writing /root/2018-10-25_08-27-43/xtrabackup_info
181025 08:27:47 [00] ...done
xtrabackup: Transaction log of lsn (2605677) to (2605686) was copied. #已複製lsn(2605677)到(2605686)的事務日誌。
181025 08:27:48 completed OK!       #完成好了!

在當前目錄下會生成一個以當前時間為名字的一個目錄:

#這裡面就是相關的備份檔案,同樣也可以看到我們建立的庫的名稱

使用以下命令使相關資料性檔案保持一致性狀態
[[email protected] ~]# innobackupex --apply-log  /root/2018-10-25_08-27-43/

xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=1 --redo-log-version=1
xtrabackup: recognized client arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=1 --redo-log-version=1
181025 08:57:41 innobackupex: Starting the apply-log operation

IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".

innobackupex version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
xtrabackup: cd to /root/2018-10-25_08-27-43/
xtrabackup: This target seems to be not prepared yet.
InnoDB: Number of pools: 1
xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(2605677)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 2605677
InnoDB: Doing recovery: scanned up to log sequence number 2605686 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.7.19 started; log sequence number 2605686

xtrabackup: Recovered WSREP position: bbe63ad7-d767-11e8-9ffc-073dc1824390:8
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2605783
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Setting log file ./ib_logfile101 size to 48 MB
InnoDB: Setting log file ./ib_logfile1 size to 48 MB
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=2605783
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 2606092
InnoDB: Doing recovery: scanned up to log sequence number 2606101 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.7.19 started; log sequence number 2606101
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2606120
181025 08:57:48 completed OK!

恢復

先刪除相應的表
注:這裡需要注意的是沒有刪除庫,因為刪除庫後恢復時會報錯,因為它找不到相應的庫,要新建出來相應名字的庫再恢復
mysql -uroot -p
mysql> drop table opop.user;
mysql> select * from opop.user;
ERROR 1146 (42S02): Table 'opop.user' doesn't exist
mysql> use opop;
mysql> show tables;
mysql> exit
[[email protected] ~]# innobackupex  --defaults-file=/etc/my.cnf  --copy-back  /root/2018-10-25_08-27-43/

注:這裡一定要記得重啟,且在Percona XtraDB叢集中主節點和其他節點的啟動、重啟方式不一樣,因為該文件是接上一篇文件

登陸到資料庫中檢視恢復情況

Xtrabackup增量備份與恢復

增量備份僅能應用於InooDB或XtraDB表,對於MyISAM表,增量與全備相同,在上面的基礎上繼續建立一個opop2的庫然後在opop-2的庫裡建一張表並插入資料

mysql> create database opop2 charset='utf8mb4';
mysql> use opop2;
mysql> create table user2(id int unsigned primary key auto_increment,name varchar(30));
mysql> insert into user2(name) values('zhangsan'),('lisi'),('wangwu'),('maliu');
mysql> commit;
mysql> select * from user2;

備份開始:

                  略去中間部分.....

#--incremental  /backup/     指定增量備份檔案備份的目錄

#--incremental-basedir       指定上一次全備或增量備份的目錄

刪除一條資料來測試增量恢復   (這裡刪除的是增量備份的資料)

mysql -uroot -p
mysql> use opop2;
mysql> show tables;
mysql> desc user2;
mysql> delete from user2 where name='lisi';
mysql> select * from user2;          #確認lisi使用者已經刪除
mysql> exit

增量恢復操作過程如下
[[email protected] ~]# innobackupex --apply-log --redo-only /root/2018-10-25_08-27-43/   #第一次的全域性備份資料目錄
[[email protected] ~]# innobackupex --apply-log --redo-only /root/2018-10-25_08-27-43/ --incremental-dir=/root/2018-10-25_11-00-25/      #第二次的增量備份資料目錄
注:這裡相當於一個合併的動作

恢復全部資料:
[[email protected] ~]# innobackupex --defaults-file=/etc/my.cnf --copy-back /root/2018-10-25_08-27-43/

                    省略中間的一部分..........

[[email protected] data]# systemctl restart [email protected]             

#因為該實驗中是做的Percona XtraDB Cluster叢集,所以使用該命令,如不是Percona XtraDB Cluster 叢集,在centos上則使用 systemctl 或 service 啟動或重啟

[[email protected] data]# mysql -uroot -p

相關推薦

Mysql中-Xtrabackup備份恢復應用

images 選項 SQ oca memory 使用方法 doc 如果 def 關於Xtrabackup(又或innobackupex)的介紹,詳細參考官方文檔 Xtrabackup安裝指南 文件準備 [root@wuxiang11 ~]# cd percona-xtr

xtrabackup 備份恢復

                  該文章接上一篇文章: 核心方面: $ cat /etc/centos-release   CentOS Linux release 7.4.1708 (Core) $ uname -r   3.10.0-693.el7.x86_64 下載安裝xtrabackup:$ w

如何用Percona XtraBackup進行MySQL從庫的單表備份恢復【轉】

empty lec del bsp 重建表 nbsp 創建 cfg serve 前提 應該確定采用的是單表一個表空間,否則不支持單表的備份與恢復。 在配置文件裏邊的mysqld段加上 innodb_file_per_table = 1 環境說明: 主庫

表中 的數據 備份 恢復

delete -- lac values reat varchar let color into -- 建表 create table emp( sid int(8) primary key, sname varchar(10), sex varchar(2), chu

GIt的備份恢復

gitlab備份 恢復 1、GItlab備份Gitlab默認的備份路徑都是在配置文件中指定的,所以我們可以去配置文件中查看vim /etc/gitlab/gitlab.rb# gitlab_rails[‘manage_backup_path‘] = true # gitlab_rails[‘backu

Ubuntu14.04如何備份恢復系統

軟件 現在 完整 force 告訴 and 擴展 體積 讓我 http://www.cnblogs.com/alexanderkun/p/5008514.html 本文由魔鬼艦長為您整理編寫。安裝好Ubuntu之後,別忘了安裝 for linux 防火墻和殺毒軟件。在備

使用xtrabackup備份還原mysql的多實例

xtrabackup1、安裝percona-xtrabackup# 下載安裝包:# cd /usr/local/src # wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.3.2/binary/redhat/6/x8

20170623_oracle備份恢復_常見問題

為什麽 exp 程序 模式 imp 全備 命令 恢復 bsp 1 為什麽需要備份?備份分類?   1)故障、遷移、誤操作   2)備份分類:       物理與邏輯角度:物理備份、邏輯備份       備份策略角度:完全備份、增量備份、差異備份 2 使用導入導出進

linux 系統備份恢復

系統 版本 備份命令 是你 nor 例子 dir del log 轉自:http://blog.csdn.net/sunnylgz/article/details/8055315 在 使用Ubuntu之前,相信很多人都有過使用Windows系統的經歷。如果你備份過Wind

postgresql數據庫備份恢復(超快)

我們 其中 -- 數據庫 過程 back 手動 文件導入 必須 PostgreSQL自帶一個客戶端pgAdmin,裏面有個備份,恢復選項,也能對數據庫進行備份 恢復(還原),但最近發現數據庫慢慢龐大的時候,經常出錯,備份的文件過程中出錯的幾率那是相當大,手動調節灰常有限。所

Linux下MySQL的備份恢復

mysql備份 再也不用擔心數據丟失了 MySQL備份的原因 1. 災難恢復 2. 審計 3. 測試1234512345mysql的備份類型 1. 根據服務器的在線狀態: 熱備:服務器處於運行狀態 冷備:服務器出去停止狀態 溫備:服務器處於半離線狀態,只能讀,但是不能

數據庫備份恢復

file str ase 數據庫 .sql 使用 geo spec ecif mysqldump命令備份:將數據庫中的數據備份成一個文本文件,表結構和表中的數據將存儲在生成的文本中。 ->工作原理:先查出需要備份的表結構,再在文本文件中生成一個create語句,然後將

Oracle 的備份恢復

改變 方式 冷備份 div 可能 例子 數據庫 速度 外部 Oracle數據庫有三種標準的備份方法,它們分別是導出/導入(EXP/IMP)、熱備份和冷備 份。導出備件是一種邏輯備份,冷備份和熱備份是物理備份。 一、 導出/導入(Export/Import) 利用

elasticsearch snapshot快照備份恢復

pre 需要 位置 oca wait _for 通過 ati tom 環境:mac   使用brew 安裝elasticsearch 1.在 /usr/local/etc/elasticsearch/elasticsearch.yml 文件中配置快照地址 p

三種VMware數據備份恢復方法

vm備份方法 服務器虛擬化,尤其是VMware形式的服務器虛擬化使IT人員獲益良多,這麽說一點也不為過。據我們所見,服務器虛擬化能解決服務器擴張、資源消耗、服務器擴張、能源消耗、高可用性等相關問題。服務器虛擬化也使我們有更多的時間解決其它的迫切問題,如企業資源預案升級、存儲項目再三遷移。  盡管VMw

iptables規則備份恢復,firewalld的9個zone,firewalld關於zone的操作,firewalld關於service的操作

firewalld service zone iptables 筆記內容:l 10.19 iptables規則備份和恢復l 10.20 firewalld的9個zonel 10.21 firewalld關於zone的操作l 10.22 firewalld關於service的操作筆記日期:201

oracle數據庫熱備中的備份恢復及例子

cache 歸檔日誌 status taf track bms 成員 運行 flat 手工熱備(開庫狀態) 備份控制文件: alter database backup controlfile to ‘/u01/oradata/prod/con.bak1‘; 備份數據文

mysql的備份恢復

mysql的備份mysql的備份和恢復備份類型:完全備份指的是備份整個數據集( 即整個數據庫 )部分備份指的是備份部分數據集(例如: 只備份一個表)增量備份指的是備份自上一次備份以來(增量或完全)以來變化的數據; 特點: 節約空間、還原麻煩 差異備份指的是備份自上一次完全備份以來變化的數據 特點: 浪費空間、

數據庫 之 數據備份恢復概念

負載 實現 黑客 sql 復數 狀態 sel 環境 需要 本文主要介紹數據備份和恢復的相關概念備份:存儲的數據副本; 原始數據:持續改變;恢復:把副本應用到線上系統; 僅能恢復至備份操作時刻的數據狀態; 時間點恢復:通過binary logs實現基於時間點的恢復; 為什麽備

10.19 iptables規則備份恢復 10.20 firewalld的9個zone 10.21

nag image 分享圖片 lld color cto .com shadow images 七周五次課10.19 iptables規則備份和恢復10.20 firewalld的9個zone10.21 firewalld關於zone的操作10.22 firewalld關於