Percona XtraBackup備份數據庫關於數據路徑默認選擇和show variables

Percona XtraBackup下載地址node

https://www.percona.com/downloads/XtraBackup/LATEST/mysql

Percona XtraBackup提供了xtrabackup和innobackupex兩個工具sql

1,xtrabackup只能備份InnoDB和XtraDB兩種數據表,而不能備份MyISAM數據表數據庫

2,innobackupex是參考了InnoDB Hotbackup的innoback腳本修改而來的.innobackupex是一個perl腳本封裝,封裝了xtrabackup。主要是爲了方便的 同時備份InnoDB和MyISAM引擎的表,但在處理myisam時須要加一個讀鎖。而且加入了一些使用的選項。如slave-info能夠記錄備份恢 復後,做爲slave須要的一些信息,根據這些信息,能夠很方便的利用備份來重作slave。bash

全數據庫備份:app

[root@ms01 /backup ] # innobackupex --user=aolens --password=*** /backup/
 
Error: option 'datadir' has different values:
'.' in defaults file
'/usr/local/mysql/data/' in SHOW VARIABLES

報錯datadir默認是當前路徑,show variables是/usr/local/mysql/datasocket

查看數據庫datadir的值:show global variables like '%datadir%';ide

查看配置文件發現配置文件裏沒有datadir參數的定義,爲配置文件添加上datadir=/usr/local/mysql/data工具

[root@ms01 ~] # innobackupex --defaults-file=/etc/my.cnf --user=aolens --password=aolens /backup/
 
160113 11:08:55 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!" .
 
160113 11:08:55 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock' as 'aolens' (using password: YES).
160113 11:08:55 version_check Connected to MySQL server
160113 11:08:55 version_check Executing a version check against the server...
160113 11:08:55 version_check Done.
160113 11:08:55 Connecting to MySQL server host: localhost, user: aolens, password: set , port: 3306, socket: /tmp/mysql .sock
Using server version 5.5.29-log
innobackupex version 2.3.2 based on MySQL server 5.6.24 Linux (x86_64) (revision id : 306a2e0)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/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:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
160113 11:08:55 >> log scanned up to (23706694302)
xtrabackup: Generating a list of tablespaces
160113 11:08:55 [01] Copying . /ibdata1 to /backup//2016-01-13_11-08-55/ibdata1
160113 11:08:56 >> log scanned up to (23706694560)
160113 11:08:56 [01] ... done
160113 11:08:57 >> log scanned up to (23706694560)
Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
160113 11:08:57 Executing FLUSH TABLES WITH READ LOCK...
160113 11:08:57 Starting to backup non-InnoDB tables and files
 
...
 
160113 11:09:13 [00] ... done
160113 11:09:13 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point ( for incremental): '23706694560'
xtrabackup: Stopping log copying thread.
.160113 11:09:13 >> log scanned up to (23706694560)
 
160113 11:09:13 Executing UNLOCK TABLES
160113 11:09:13 All tables unlocked
160113 11:09:13 Backup created in directory '/backup//2016-01-13_11-08-55'
MySQL binlog position: filename 'mysql-bin.000032' , position '286360161'
160113 11:09:13 [00] Writing backup-my.cnf
160113 11:09:13 [00] ... done
160113 11:09:13 [00] Writing xtrabackup_info
160113 11:09:13 [00] ... done
xtrabackup: Transaction log of lsn (23706693241) to (23706694560) was copied.
160113 11:09:13 completed OK!

備份成功spa

因此在使用xtrabackup時必定要注意,在配置文件裏寫上datadir的路徑,否則數據還原也會出錯。

單庫備份

1
[root@ms01 /backup ] # innobackupex --defaults-file=/etc/my.cnf --user=aolens --password=*** --database=recon /backup/

數據還原

提交未提交的數據

innobackupex --apply-log /backup/2016-01-13_11-08-55/

innobackup不支持離線備份,可是恢復無需啓動MySQL。

刪除數據目錄下的一個庫目錄。執行恢復。

[root@node2 data] # innobackupex --copy-back /backup/2016-01-13_11-08-55/
innobackupex: Error: Original data directory '/mydata/data' is not empty! at /usr/bin/innobackupex line 2163. #報錯數據目錄不爲空!
[root@node2 data] # rm -rf * #刪除數據目錄下的全部文件。
[root@node2 data] # innobackupex --copy-back /backup/2016-01-13_11-08-55/
innobackupex: Finished copying back files.
140909 02:58:36 innobackupex: completed OK!

修改恢復回來的數據的權限

chown -R mysql.mysql /usr/local/mysql/data

啓動mysql便可


http://www.aolens.cn/?p=862

相關文章
相關標籤/搜索