xtraback是物理备份,非阻塞在线实时备份
1.优点:

  • 备份速度很快
  • 备份期间不中断事务
  • 通过压缩节约网络和磁盘
  • 自动备份验证
  • 恢复快

官网提示:

  • Fast and reliable backups
  • Uninterrupted transaction processing during backups
  • Savings on disk space and network bandwidth with better compression
  • Automatic backup verification
  • Higher uptime due to faster restore time

2.备份原理
xtrabackup 会有两个线程,当copy InnoDB的data files时,同时会在后台再开一个线程用来copy redo log(有变化的)
当数据库支持备份时,xtrabackup 将会第一时间先备份InnoDB data,执行LOCK TABLES FOR BACKUP 来copy非事务表和.frm 文件。当这些完成以后,就会备份 .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, .par, and .opt files.
然后xtrabackup 会用 LOCK BINLOG FOR BACKUP 来防止改变二进制日志位置的操作。随后会完成二进制日志复制并记录位置。copy完成后,便会释放所有的锁
最后,二进制日志被记录,xtrabackup 正常退出返回0

原文
Percona XtraBackup will use Backup locks where available as a lightweight alternative to FLUSH TABLES WITH READ LOCK. This feature is available in Percona Server 5.6+. Percona XtraBackup uses this automatically to copy non-InnoDB data to avoid blocking DML queries that modify InnoDB tables. When backup locks are supported by the server, xtrabackup will first copy InnoDB data, run the LOCK TABLES FOR BACKUP and copy the MyISAM tables and .frm files. Once this is done, the backup of the files will begin. It will backup .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, .par, and .opt files
After that xtrabackup will use LOCK BINLOG FOR BACKUP to block all operations that might change either binary log position or Exec_Master_Log_Pos or Exec_Gtid_Set (i.e. master binary log coordinates corresponding to the current SQL thread state on a replication slave) as reported by SHOW MASTER/SLAVE STATUS. xtrabackup will then finish copying the REDO log files and fetch the binary log coordinates. After this is completed xtrabackup will unlock the binary log and tables.

Finally, the binary log position will be printed to STDERR and xtrabackup will exit returning 0 if all went OK.

3.恢复
恢复备份时,可以用参数--copy-back 或者是 --move-back
xtrabackup 会读取my.cnf 中的变量datadir,innodb_data_home_dir,innodb_data_file_path,innodb_log_group_home_dir 并且检测 文件夹是否存在
他会先copy MyISAM tables, indexes。例如(.frm,MGR,MYI,TRG等),然后是copy innodb 表和索引,还有日志文件。在copy文件的时候,保留文件的属性,在启动MySQL服务器之前,将文件的权限改为MySQL,他们被创建的用户所拥有的

还有,--move-back 也可以用来恢复备份,他很像--copy-back ,唯一不同的是他会移除本地的本分文件,必须谨慎使用此选项。在磁盘不够用的情况下,使用此选项比较有用