mysql xtrabackup工具备份

一、注意事项

  建议用xtrabackup备份时采用全备或增量备份的方式,楼主也尝试过单库备份,但是都以备份后恢复到已经存在数据库的mysqldata目录下后部分库会出幺蛾子而告终,建议使用mysqldump备份部分库。

二、安装

  yum install  http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm  #下载percona公司的rpm依赖包

  yum list | grep percona

  yum install percona-xtrabackup-24 -y #安装xtrabackup

三、全量备份与恢复

  1、备份

    innobackupex --defaults-file=/data/3306/my.cnf --user=root -S /data/3306/mysql.sock --password="xxx" --backup /data/backup/xtrabackup/  #将数据目录备份到 /data/backup/xtrabackup/下,完成后该目录下会生成相应的时间戳目录然后所有的备份文件会放在目录中

  2、恢复准备

    innobackupex --apply-log /data/backup/xtrabackup/2017-12-04_13-57-29/(此目录为备份后的目录)  

    #使用此--apply-log参数使用相关数据性文件保持一致性状态

  3、恢复到数据库

    a、首先清空数据目录

      rm -rf /Registry/fof2_mysql/mysql3308/mysql_data/*

    b、 正式恢复

      innobackupex --defaults-file=/data/3308/my.cnf  --copy-back  /data/backup/xtrabackup/2017-12-04_13-57-29/(配置文件my.cnf中已经配置datadir=/Registry/fof2_mysql/mysql3308/mysql_data/

    c、给数据目录mysql权限

      chow -R mysql:mysql /Registry/fof2_mysql/mysql3308/mysql_data

  4、特别注意事项

    若数据库版本不一致,需要使用命令 mysql_upgrade -u root -p 进行修复。

四、增量备份

  1、注意事项

    需要注意的是,增量备份仅能应用于InooDB或XtraDB表,对于MyISAM表,增量与全备相同

  2、

引用自:https://blog.csdn.net/wfs1994/article/details/80396604

https://www.cnblogs.com/youkanyouxiao/p/8335173.html

https://blog.csdn.net/heizistudio/article/details/23937935

 

  

xtrabackup --user=pycf --password=pycf@2018 --host=127.0.0.1 --datadir=/application/mysql3306/mysql_data/ --databases=wohaoshuai --backup --target-dir=/application/data/backup/xtrabackup/

五、xtrabackup 全量和增量备份(若要备份全量则参考增量中的全量即可)

  1、备份:

全量:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --user=root --password="123456" --port=3308 --backup --target-dir=/application/backup/mysql/full_incre_aaa

创库一表一后第一次增量备份:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --backup --user=root --password="123456" --port=3308 --target-dir=/application/backup/mysql/incre_1/ --incremental-basedir=/application/backup/mysql/full_incre_aaa

创库二表二后第二次增量备份:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --backup --user=root --password="123456" --port=3306 --target-dir=/application/backup/mysql/incre_2/ --incremental-basedir=/application/backup/mysql/incre_1/

创库三表三后第三次增量备份:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --backup --user=root --password="123456" --port=3306 --target-dir=/application/backup/mysql/incre_3/ --incremental-basedir=/application/backup/mysql/incre_2/

  2、恢复准备:
全备恢复准备:

xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --prepare --user=root --password="123456" --apply-log-only --target-dir=/application/backup/mysql/full_incre_aaa

第一次增量恢复准备:

xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --prepare --user=root --password="123456" --apply-log-only --target-dir=/application/backup/mysql/full_incre_aaa --incremental-dir=/application/backup/mysql/incre_1/

第二次增量恢复准备:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --prepare --user=root --password="123456" --apply-log-only --target-dir=/application/backup/mysql/full_incre_aaa --incremental-dir=/application/backup/mysql/incre_2/

第三次增量恢复准备:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --prepare --user=root --password="123456" --apply-log-only --target-dir=/application/backup/mysql/full_incre_aaa --incremental-dir=/application/backup/mysql/incre_3/

  3、恢复:
开始恢复:
xtrabackup --defaults-file=/application/mysql3308/my.cnf -S /application/mysql3308/logs/mysql.sock --prepare --user=root --password="123456" --target-dir=/application/backup/mysql/full_incre_aaa

先停止mysql
/application/mysql3308/bin/mysqladmin -uroot -S /application/mysql3308/logs/mysql.sock -p shutdown

开始同步数据:
cd /application/backup/mysql/full_incre_aaa

rsync -rvt --exclude 'xtrabackup_checkpoints' --exclude 'xtrabackup_logfile' ./ /application/mysql3308/mysql_data

chow -R mysql. /application/mysql3308

启动mysql
/application/mysql3308bin/mysqld_safe --defaults-file=/application/mysql3308/my.cnf --user=mysql &

posted @ 2018-07-13 10:47  Presley  阅读(228)  评论(0编辑  收藏  举报