xtrabackup之Innobackupex全备数据库

时间:2023-03-08 19:36:21

一、Xtrabackup是什么:

  • Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。
  • Xtrabackup有两个主要的工具:xtrabackup、innobackupex
  1. xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表
  2. innobackupex是参考了InnoDB Hotbackup的innoback脚本修改而来的.innobackupex是一个perl脚本封装,封装了xtrabackup。主要是为了方便的 同时备份InnoDB和MyISAM引擎的表,但在处理myisam时需要加一个读锁。并且加入了一些使用的选项。如slave-info可以记录备份恢 复后,作为slave需要的一些信息,根据这些信息,可以很方便的利用备份来重做slave。

二、利用二进制包安装xtrabackup

[root@DBMysql ~]# tar xvfz percona-xtrabackup-2.0.-.tar.gz -C /usr/local
[root@DBMysql local]# mv percona-xtrabackup-2.0. xtrabackup
[root@DBMysql local]# chown mysql:mysql -R /usr/local/xtrabackup/ 在mysql用户下的 .bash_profile文件中添加环境变量
export PATH=/usr/local/xtrabackup/bin:$PATH

三、创建备份专用账户

[mysql@DBMysql ~]$ mysql --defaults-file=/mysql/mysqldata//my.cnf -usystem -p''
[(none) ::]>create user xtrabk@'127.0.0.1' identified by 'onlybackup';
Query OK, rows affected (0.08 sec) [(none) ::]>grant reload,lock tables,Replication client, super on *.* to xtrabk@'127.0.0.1';
Query OK, rows affected (0.07 sec)
[(none) ::]>

四.innobackupex全量备份

[mysql@hadoop1 ~]$ innobackupex --defaults-file=/mysql/mysqldata//my.cnf --host=127.0.0.1 --user=xtrabk --password='onlybackup' /mysql/mysqldata/backup/3306_full

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright ,  Innobase Oy
and Percona Ireland Ltd -. All Rights Reserved. This software is published under
the GNU GENERAL PUBLIC LICENSE Version , June . :: innobackupex: Starting mysql with options: --defaults-file='/mysql/mysqldata/3306/my.cnf' --password=xxxxxxxx --user='xtrabk' --host='127.0.0.1' --unbuffered --
:: innobackupex: Connected to database with mysql child process (pid=)
:: innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!". innobackupex: Using mysql Ver 14.12 Distrib 5.0., for redhat-linux-gnu (x86_64) using readline 5.1
innobackupex: Using mysql server version Copyright (c) , , Oracle and/or its affiliates. All rights reserved. innobackupex: Created backup directory /mysql/mysqldata/backup/3306_full/--27_00--
:: innobackupex: Starting mysql with options: --defaults-file='/mysql/mysqldata/3306/my.cnf' --password=xxxxxxxx --user='xtrabk' --host='127.0.0.1' --unbuffered --
:: innobackupex: Connected to database with mysql child process (pid=)
:: innobackupex: Connection to database server closed :: innobackupex: Starting ibbackup with command: xtrabackup_56 --defaults-file="/mysql/mysqldata/3306/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/mysql/mysqldata/backup/3306_full/--27_00-- --tmpdir=/mysql/mysqldata//tmp
innobackupex: Waiting for ibbackup (pid=) to suspend
innobackupex: Suspend file '/mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05/xtrabackup_suspended' xtrabackup_56 version 2.0. for MySQL server 5.6. Linux (x86_64) (revision id: )
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /mysql/mysqldata//data
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata01:100M:autoextend
xtrabackup: innodb_log_group_home_dir = /mysql/mysqldata//redo
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: using O_DIRECT
InnoDB: Allocated tablespace , old maximum was
InnoDB: Opened undo tablespaces
>> log scanned up to ()
[] Copying ./ibdata01 to /mysql/mysqldata/backup/3306_full/--27_00--/ibdata01
>> log scanned up to ()
[] ...done
[] Copying ./mysql/innodb_table_stats.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/mysql/innodb_table_stats.ibd
>> log scanned up to ()
[] ...done
[] Copying ./mysql/innodb_index_stats.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/mysql/innodb_index_stats.ibd
[] ...done
[] Copying ./mysql/slave_relay_log_info.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/mysql/slave_relay_log_info.ibd
[] ...done
[] Copying ./mysql/slave_master_info.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/mysql/slave_master_info.ibd
[] ...done
[] Copying ./mysql/slave_worker_info.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/mysql/slave_worker_info.ibd
[] ...done
[] Copying ./pls_innodb/t_polestar02.ibd to /mysql/mysqldata/backup/3306_full/--27_00--/pls_innodb/t_polestar02.ibd
[] ...done
[] Copying /mysql/mysqldata//undo/undo001 to /mysql/mysqldata/backup/3306_full/--27_00--/undo001
[] ...done
[] Copying /mysql/mysqldata//undo/undo002 to /mysql/mysqldata/backup/3306_full/--27_00--/undo002
[] ...done
[] Copying /mysql/mysqldata//undo/undo003 to /mysql/mysqldata/backup/3306_full/--27_00--/undo003
[] ...done
[] Copying /mysql/mysqldata//undo/undo004 to /mysql/mysqldata/backup/3306_full/--27_00--/undo004
>> log scanned up to ()
[] ...done
[] Copying /mysql/mysqldata//undo/undo005 to /mysql/mysqldata/backup/3306_full/--27_00--/undo005
[] ...done
>> log scanned up to () :: innobackupex: Continuing after ibbackup has suspended
:: innobackupex: Starting mysql with options: --defaults-file='/mysql/mysqldata/3306/my.cnf' --password=xxxxxxxx --user='xtrabk' --host='127.0.0.1' --unbuffered --
:: innobackupex: Connected to database with mysql child process (pid=)
>> log scanned up to ()
>> log scanned up to ()
:: innobackupex: Starting to lock all tables...
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
>> log scanned up to ()
:: innobackupex: All tables locked and flushed to disk :: innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/mysql/mysqldata/3306/data'
innobackupex: Backing up files '/mysql/mysqldata/3306/data/mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' ( files)
innobackupex: Backing up files '/mysql/mysqldata/3306/data/performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' ( files)
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_innodb/db.opt'
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_innodb/t_polestar02.frm'
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.MYD'
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_myisam/db.opt'
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.MYI'
innobackupex: Backing up file '/mysql/mysqldata/3306/data/pls_myisam/t_polestar01.frm'
:: innobackupex: Finished backing up non-InnoDB tables and files :: innobackupex: Waiting for log copying to finish xtrabackup: The latest check point (for incremental): ''
xtrabackup: Stopping log copying thread.
.>> log scanned up to () xtrabackup: Transaction log of lsn () to () was copied.
:: innobackupex: All tables unlocked
:: innobackupex: Connection to database server closed innobackupex: Backup created in directory '/mysql/mysqldata/backup/3306_full/2016-05-27_00-23-05'
innobackupex: MySQL binlog position: filename 'mysql-bin.000003', position
:: innobackupex: completed OK!
[mysql@hadoop1 ~]$

五、innobackupexe备份产生的相关文件

[mysql@hadoop1 --27_00--]$ ls -l
total
-rw-rw-r-- mysql mysql May : backup-my.cnf
-rw-rw---- mysql mysql May : ibdata01
drwx------ mysql mysql May : mysql
drwxrwxr-x mysql mysql May : performance_schema
drwx------ mysql mysql May : pls_innodb
drwxrwxr-x mysql mysql May : pls_myisam
drwxrwxr-x mysql mysql May : test
-rw-rw---- mysql mysql May : undo001
-rw-rw---- mysql mysql May : undo002
-rw-rw---- mysql mysql May : undo003
-rw-rw---- mysql mysql May : undo004
-rw-rw---- mysql mysql May : undo005
-rw-rw-r-- mysql mysql May : xtrabackup_binary
-rw-rw-r-- mysql mysql May : xtrabackup_binlog_info
-rw-rw---- mysql mysql May : xtrabackup_checkpoints
-rw-rw---- mysql mysql May : xtrabackup_logfile
[mysql@hadoop1 --27_00--]$