Mysql xtrabackup 之creating a backup

2070阅读 0评论2014-01-08 zxszcaijin
分类:Mysql/postgreSQL

   上次在线搭建slave的时候,出现了一些问题,这次对xtrabackup进行了系统的学习,把文档中学到的东西记录下来。
 
   xtrabackup是percona在线备份的开源工具,其优点之一就是备份innodb表的时候不需要任何锁表,对于目前oltp系统来说,提高了系统的可用率。
   xtrabackup是如何来防止锁表,而又提供备份的功能呢?其实xtrabackup在备份的时候,做了以下两样事情: 
  [1]  It starts a log-copying thread in the background. This thread watches the InnoDB log files, and when they change, it copies the changed blocks
        
to a file calledxtrabackup_logfile in the backup target directory. This is necessary because the backup might take a long time,    and the recovery
        process needs all of the log file entries from the beginning to the end of the backup.
  [2]  It copies the InnoDB data files to the target directory. This is not a simple file copy; it opens and reads the files similarly to the  wayInnoDB does,
        by reading the data dictionary and copying them a page at a time
 
以上的解释如下:
  [1]  xtrabackup在后台启动了一个log_copying线程,负责监视innodb的logfile,一旦发现logfile有改动,就会将这些改动的blocks记录到一个xtrabackup_logfile
        的文件中,后续的恢复会使用这个文件的日志(这个文件的目录由运行时指定的--target-dir参数指定.备份/恢复的时间开销与数据库数据的大小,和备份这
        段时
间内生成的日志文件的大小有关)
  [2]   xtrabackup会复制所有的数据文件到--target-dir所指定的目录中。xtrabackup并不是一个简单的文件copy,而是采用 innodb读取数据文件内容的方式,copy
        相应的page到--target-dir指定的目录下的相关文件中。当备份结束后,xtrabackup停止log-copying线程,并在目标目录中生成一个叫做xtrabackup_check
        points的文件,文件中包含backup的类型(全备还是增量备份),
备份期间生成日志起止 LSN。

       一个简单的全量备份操作如下:
        xtrabackup --backup --datadir=/data/datacenter --target-dir=/data/xiaocai/。
        备份的数据文件的位置为datadir指定的位置,备份的目标目录为/data/xiaocai/。
        xtrabackup在线备份,搭建slave,对于一些24*7的oltp系统或许是一个好的解决方案。
  •   
          这篇文章只对xtrabackup做一个简单的介绍,后续会对xtrabackup作更详细的描述.
  • 上一篇:Myths about MyISAM
    下一篇:replication原理和常见搭建