zoukankan      html  css  js  c++  java
  • MySQL innobackupex 全备+增量备份+还原+增量还原

    1、全备

    [root@test3 ~]# innobackupex --user=root --password=123456 --no-timestamp /data/backup/full_backup

    [root@test3 backup]# ls #全部备份的文件
    full_backup

    2、对数据做一些修改

    mysql> use sbtest;    #创建了一张表,然后插入了两条记录
    Database changed
    mysql> create table tb3(a varchar(5), sysTime datetime);
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> insert into tb3 select "aa", now();
    Query OK, 1 row affected (0.01 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> insert into tb3 select "bb", now();
    Query OK, 1 row affected (0.01 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> select * from tb3;
    +------+---------------------+
    | a    | sysTime             |
    +------+---------------------+
    | aa   | 2018-11-29 09:14:00 |
    | bb   | 2018-11-29 09:14:11 |
    +------+---------------------+
    2 rows in set (0.00 sec)

    3、开始增量备份

    [root@test3 backup]# innobackupex --user=root --password=123456 --no-timestamp --incremental /data/backup/incre1 --incremental-basedir=/data/backup/full_backup
    
    --no-timestamp:选项来阻止命令自动创建一个以时间命名的目录,我们可以自定义备份集的名字
    --incremental /data/backup/incre1 :参数说明这次备份时一个增量备份,后面的路径指定增量备份的目录
    --incremental-basedir=/data/backup/full_backup :增量备份时基于全备的,这个参数就是说明本次的增量备份时基于那次的全备,指向全备的目录文件

        查看增量备份的文件记录:

    [root@test3 incre1]# cat xtrabackup_checkpoints
    backup_type = incremental                 #备份类型
    from_lsn = 13741583205                    #需要说明增量备份只能INNODB,xtrack存储引擎,备份是基于lsn的改变的! 
    to_lsn = 13741590096
    last_lsn = 13741590105
    compact = 0
    recover_binlog_info = 0

    备份完成之后,我们需要恢复操作,准备数据,也就是redo已经提交的事务,回滚未提交的事务。增量备份也是这样,但是操作有些不同。

    4、恢复

    [root@test3 ~]# innobackupex  --apply-log --redo-only --use-memory=1G /data/backup/full_backup
    
    --use-memory=1G #表示使用的内存大小
    --redo-only:这个选项在prepare base full backup,往其中merge增量备份(但不包括最后一个)时候使用
    第二步:把增量备份在全备上面回放,也就是把增量备份附加到全备上。 
    [root@test3
    ~]# innobackupex --apply-log --redo-only /data/backup/full_backup --incremental-dir=/data/backup/incre1

    整个恢复操作分为两步:

    1:准备全部备份,保证文件的一致性。
    2:把所有的增量备份附加到全备备份上。如果有多个增量备份,则每一个增量备份文件都要执行附加操作。但是要注意顺序,可以查看增量备份的xtrabackup_checkpoints文件
       根据lsn来确定文件的顺序
    [root@test3 ~]# service mysqld  stop
    
    [root@test3 ~]# rm -fr /data/mysql/*
    
    [root@test3 ~]# innobackupex --copy-back /data/backup/full_backup
    
    [root@test3 ~]# chown -R mysql:mysql /data/mysql/
    
    #启动数据库,若是之前插入的两条数据存在,则说明增量备份恢复成功!
    [root@test3 ~]# service mysqld start
    Starting MySQL... SUCCESS! 
    [root@test3 ~]# mysql -uroot -p123456
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.22-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> use sbtest;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> select * from tb3;       #增量备份插入的数据存在
    +------+---------------------+
    | a    | sysTime             |
    +------+---------------------+
    | aa   | 2018-11-29 09:14:00 |
    | bb   | 2018-11-29 09:14:11 |
    +------+---------------------+
    2 rows in set (0.00 sec)

    特别提示:
    若有多个增量备份,则每一个增量备份都要重放到全备的文件中,一定要注意重放增量备份时候的顺序,可以在xtrabackup_checkpoints文件中根据lsn的大小来判断文件的顺序。

    5、流压缩

    [root@test2 backup]# innobackupex --user=root --password="7abec53701c3eefb" --no-timestamp --socket=/var/lib/mysql/mysql.sock --stream=tar /tmp |gzip -> testdb.tar.gz
    
    --stram=tar  : 指定标准输出格式,一种是tar,另一种是xbstream;xbstream是xtraceback提供的,解压的时候需要专用命令处理,考虑通用性,选择用tar!
    
    /tmp         : 流格式标准输出,临时存放于/tmp目录下面
    
    | gzip ->    : 通过管道把流格式输出传给gzip进行压缩

    转:https://www.cnblogs.com/wxzhe/p/10033983.html

  • 相关阅读:
    HttpModule
    phpcms(1)
    ajax,json
    ajax 参数 小记
    PHP中文件操作基础:目录操作,文件操作
    PHP,获取文件夹下所有文件数量的方法。
    PHP中文件操作基础:文件路径基础
    js,jquery基础使用方法
    PHP基础知识测试题
    PHP中单例模式与工厂模式,
  • 原文地址:https://www.cnblogs.com/hankyoon/p/14774450.html
Copyright © 2011-2022 走看看