加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

利用mysqldump和mysqlbinlog实现完全备份和增量备份

(2017-11-26 23:26:31)
标签:

mysqldump

mysqlbinlog

mysql完全备份

mysql增量备份

一、数据备份基础:

1、备份类型:

完全备份:整个数据集;

部分部分:只备份数据子集;     

增量备份:仅备份最近一次完全备份或增量备份(如果存在增量)以来变化的数据;

差异备份:仅备份最近一次完全备份以来变化的数据;

2、备份方式:

1)、与存储引擎有关:热备份、温备份、冷备份:

      热备:读写操作均可执行;

      温备:读操作可执行;但写操作不成;

      冷备:读写操作均不可进行;

2)、与存储引擎无关:物理备份、逻辑备份

      物理备份:直接复制数据文件进行备份;

      逻辑备份:从数据库中“导出”数据另存而进行的备份;

3、引擎支持的备份方式:

MyISAM:支持温备,不能热备

      InnoDB:支持热备          

4、备份时需要考虑的因素:

      持续时长、备份过程的时长、备份负载、恢复过程的时长        

5、备份什么

      数据

      二进制日志、innodb的事务日志

      代码(存储过程、存储函数、触发器、事件调度器)

      服务器的配置文件         

6、备份方案的设计:

      数据集:完全+增量;

      备份手段:物理、逻辑;     

7、备份工具:

mysqldump:逻辑备份工具,适用所有存储引擎,温备;完全备份、部分备份;对InnoDB存储引擎支持热备;

cp,tar等复制归档工具:物理备份工具,适用所有存储引擎;冷备:完全备份,部分备份;   

      mysql> SHOW BINARY|MASTER LOGS; 查看当前服务器所使用的二进制状态

      mysql> SHOW MASTER STATUS;查看当前正在使用的二进制状态

      mysql> SHOW BINLOG EVENTS IN '' FROM pos; 查看某一个指定的二进制日志中的文件内容

mysqlbinlog:查看二进制日志文件并利用其做增量备份

      mysqlbinlog [OPTION] log_file

           --start-position        从哪个位置开始做增量备份

           --stop-position        增量备份到哪个位置结束

           --start-datetime=    从哪个时间点开始做增量备份

           --stop-datetime=     增量备份到哪个时间点结束

二、备份工具详解:mysqldumpmysqlbinlog                      

1、逻辑备份工具:mysqldumpmydumper,phpMyAdmin

1)、mysqldump:客户端命令,通过mysql协议连接至mysqld服务器

      man mysqldump

      mysqldump [options] [db_name [tbl_name ...]]   

       shell> mysqldump [options] db_name [tbl_name ...]

            shell> mysqldump [options] --databases db_name ...

            shell> mysqldump [options] --all-databases

       备份的数据集:

           -A--all-databases              备份所有数据库

           -B db_name,...                备份指定数据库

           --databases db_name,...       备份指定数据库

2)引擎支持备份方式及实现:

MyISAM:只支持温备;必须锁定备份库,而后才能启动备份操作,

支持锁定的参数如下:

          --lock-all-tables, -x :锁定所有库的所有表

             --lock-tables, -l:对于每个单独的数据库,在启动备份之前锁定其所有表;

           注意:这两个参数对InnoDB表一样生效,实现温备;

      InonoDB:支持热备,可以直接启用备份,无需锁定表。

           --single-transaction

3)、其他选项:

      -E,--events:备份指定数据库相关的所有event scheduler;

      --routines, -R:备份指定数据库相关的所有存储过程和存储函数;  

      --triggers:备份表的相关的触发器;

      --master-data

           1)、记录为CHANGE MASTER TO语句,此语句不被注释;

           2)、记录为注释的CHANGE MASTER TO语句

            mysqldump --master-data=2 --all-databases > dumpfile

      --flush-logs:日志滚动

           锁定表完成后,执行flush logs命令;

2、备份建议:         

二进制日志文件不应该与数据文件放在同一磁盘;

建议还原时关闭二进制日志记录

      mysql> SHOW GLOBAL VARIABLES LIKE '%log%';

      sql_log_bin  ON

      mysql> SET sql_log_bin = OFF

三、利用mysqldump做完全备份还原

1mysqldump做部分备份和完全备份:                    

[root@www ~]# cp hellodb.sql /root/

cp: "hellodb.sql" "/root/hellodb.sql" 为同一文件

[root@www ~]# file hellodb.sql

hellodb.sql: ASCII text, with very long lines

[root@www ~]# less hellodb.sql

-- MySQL dump 10.13  Distrib 5.5.33, for Linux (x86_64)

--

-- Current Database: `hellodb`

CREATE DATABASE `hellodb` ;

USE `hellodb`;

-- Table structure for table `classes`

DROP TABLE IF EXISTS `classes`;

;

;

CREATE TABLE `classes` (

  `ClassID` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,

  `Class` varchar(100) DEFAULT NULL,

  `NumOfStu` smallint(5) unsigned DEFAULT NULL,

  PRIMARY KEY (`ClassID`)

) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

;

 

#修改MyISAM引擎为InnoDB,使其支持热备

[root@www ~]# sed -i 's/MyISAM/InonoDB/g' hellodb.sql

[root@www ~]# sed -i 's/InonoDB/InnoDB/g' hellodb.sql

[root@www ~]# less hellodb.sql

-- MySQL dump 10.13  Distrib 5.5.33, for Linux (x86_64)

--

-- Host: localhost    Database: hellodb

-- ------------------------------------------------------

-- Server version       5.5.33-log

 

-- MySQL dump 10.13  Distrib 5.5.33, for Linux (x86_64)

--

-- Host: localhost    Database: hellodb

-- ------------------------------------------------------

-- Server version       5.5.33-log

 

DROP TABLE IF EXISTS `classes`;

;

;

CREATE TABLE `classes` (

  `ClassID` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,

  `Class` varchar(100) DEFAULT NULL,

  `NumOfStu` smallint(5) unsigned DEFAULT NULL,

  PRIMARY KEY (`ClassID`)

) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

;

--

-- Dumping data for table `classes`

--

mysql> SHOW DATABASES;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| hellodb             |

| mysql               |

| test                  |

| testdb              |

+--------------------+

5 rows in set (0.04 sec)

 

mysql> use hellodb

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> SHOW TABLES;

+-------------------+

| Tables_in_hellodb |

+-------------------+

| classes            |

| coc                 |

| courses           |

| scores             |

| students          |

| teachers          |

| toc                  |

+-------------------+

7 rows in set (0.00 sec)

 

mysql> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |    NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |        NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |  NULL |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.01 sec)

mysql> \q

Bye                

[root@www ~]# mysqldump -uroot

Usage: mysqldump [OPTIONS] database [tables]

OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]

OR     mysqldump [OPTIONS] --all-databases [OPTIONS]

For more options, use mysqldump --help

[root@www ~]# mysqldump -uroot --databases hellodb

没有输出重定向则默认输出

-- MySQL dump 10.13  Distrib 5.1.73, for redhat-linux-gnu (x86_64)

-- Host: localhost    Database: hellodb

-- ------------------------------------------------------

-- Server version       5.1.73

CREATE DATABASE `hellodb` ;

.......

 

部分备份:将hellodb.sql备份到/root/hellodb.sql

[root@www ~]# mysqldump -uroot --databases hellodb > /root/hellodb.sql

[root@www ~]# ls

hellodb.sql              

[root@www ~]# mkdir /root/sqlbak

[root@www ~]# mysqldump -uroot --database hellodb >/root/sqlbak/hellodb.sql

[root@www ~]# cd sqlbak

[root@www sqlbak]# ls

hellodb.sql

[root@www sqlbak]# less hellodb.sql

-- MySQL dump 10.13  Distrib 5.1.73, for redhat-linux-gnu (x86_64)

--

-- Host: localhost    Database: hellodb

-- ------------------------------------------------------

-- Server version       5.1.73

 

CREATE DATABASE `hellodb` ;

DROP TABLE IF EXISTS `classes`;

;

;

CREATE TABLE `classes` (

  `ClassID` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,

  `Class` varchar(100) DEFAULT NULL,

  `NumOfStu` smallint(5) unsigned DEFAULT NULL,

  PRIMARY KEY (`ClassID`)

) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

;

......

 

#hellodbtestdb两个数据库都备份到/root/sqlbak/hellodb_mydb.sql

[root@www ~]# mysqldump -uroot --databases hellodb testdb > /root/sqlbak/hellodb_mydb.sql

[root@www ~]# cd sqlbak

[root@www sqlbak]# ls

hellodb_mydb.sql  hellodb.sql

[root@www sqlbak]#

[root@www sqlbak]# cd

 

备份所有数据库的数据到/root/sqlbak/all.sql文件下

[root@www ~]# mysqldump -uroot --all-databases --lock-all-tables --master-data=2 > /root/sqlbak/all.sql

mysqldump: Error: Binlogging on server not active

提示Binlogging为启动,

编辑/etc/my.cnf文件,设置log_bin=ON

[root@www etc]# vim /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log_bin=ON

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

[root@www ~]# service mysqld restart

停止 mysqld [确定]

正在启动 mysqld [确定]

[root@www ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

mysql> SHOW GLOBAL VARIABLES LIKE '%log%';

+-----------------------------------------+---------------------------------+

| Variable_name                           | Value                              |

+-----------------------------------------+---------------------------------+

| back_log                                | 50                                      |

| binlog_cache_size                       | 32768                             |

| binlog_direct_non_transactional_updates | OFF                      |

| binlog_format                           | STATEMENT                      |

| expire_logs_days                        | 0                                    |

| general_log                             | OFF                                 |

| general_log_file                        | /var/run/mysqld/mysqld.log      |

| innodb_flush_log_at_trx_commit          | 1                               |

| innodb_locks_unsafe_for_binlog          | OFF                             |

| innodb_log_buffer_size                  | 1048576                         |

| innodb_log_file_size                    | 5242880                         |

| innodb_log_files_in_group               | 2                               |

| innodb_log_group_home_dir               | ./                              |

| innodb_mirrored_log_groups              | 1                               |

| log                                     | OFF                             |

| log_bin                                 | ON                              |

| log_bin_trust_function_creators         | OFF                             |

| log_bin_trust_routine_creators          | OFF                             |

| log_error                               | /var/log/mysqld.log             |

| log_output                              | FILE                            |

| log_queries_not_using_indexes           | OFF                             |

| log_slave_updates                       | OFF                             |

| log_slow_queries                        | OFF                             |

| log_warnings                            | 1                               |

| max_binlog_cache_size                   | 18446744073709547520  |

| max_binlog_size                         | 1073741824                      |

| max_relay_log_size                      | 0                               |

| relay_log                               |                                 |

| relay_log_index                         |                                 |

| relay_log_info_file                     | relay-log.info                  |

| relay_log_purge                         | ON                              |

| relay_log_space_limit                   | 0                               |

| slow_query_log                          | OFF                             |

| slow_query_log_file                     | /var/run/mysqld/mysqld-slow.log |

| sql_log_bin                             | ON                              |

| sql_log_off                               | OFF                                  |

| sql_log_update                          | ON                                  |

| sync_binlog                               | 0                                     |

+-----------------------------------------+---------------------------------+

38 rows in set (0.00 sec)

 

mysql> SHOW MASTER LOGS;

+-----------+--------------+

| Log_name  | File_size |

+-----------+--------------+

| ON.000001 |       106 |

+-----------+--------------+

1 row in set (0.00 sec)

mysql>

 

 

[root@www ~]# vim /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log_bin=mysql-bin

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

~

"/etc/my.cnf" 11L, 269C 已写入                                                         

[root@www ~]# service mysqld restart

停止 mysqld [确定]

正在启动 mysqld [确定]

[root@www ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, 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> SHOW GLOBAL VARIABLES LIKE '%log%';

+-----------------------------------------+---------------------------------+

| Variable_name                           | Value                              |

+-----------------------------------------+---------------------------------+

| back_log                                | 50                                      |

| binlog_cache_size                       | 32768                            |

| binlog_direct_non_transactional_updates | OFF                     |

| binlog_format                           | STATEMENT                       |

| expire_logs_days                        | 0                                    |

| general_log                             | OFF                                   |

| general_log_file                        | /var/run/mysqld/mysqld.log  |

| innodb_flush_log_at_trx_commit          | 1                               |

| innodb_locks_unsafe_for_binlog          | OFF                             |

| innodb_log_buffer_size                  | 1048576                         |

| innodb_log_file_size                    | 5242880                         |

| innodb_log_files_in_group               | 2                               |

| innodb_log_group_home_dir               | ./                              |

| innodb_mirrored_log_groups              | 1                               |

| log                                     | OFF                             |

| log_bin                                 | ON                              |

| log_bin_trust_function_creators         | OFF                             |

| log_bin_trust_routine_creators          | OFF                             |

| log_error                               | /var/log/mysqld.log             |

| log_output                              | FILE                            |

| log_queries_not_using_indexes           | OFF                             |

| log_slave_updates                       | OFF                             |

| log_slow_queries                        | OFF                             |

| log_warnings                            | 1                               |

| max_binlog_cache_size                   | 18446744073709547520            |

| max_binlog_size                         | 1073741824                      |

| max_relay_log_size                      | 0                               |

| relay_log                               |                                 |

| relay_log_index                         |                                 |

| relay_log_info_file                     | relay-log.info                  |

| relay_log_purge                         | ON                              |

| relay_log_space_limit                   | 0                               |

| slow_query_log                          | OFF                             |

| slow_query_log_file                     | /var/run/mysqld/mysqld-slow.log |

| sql_log_bin                             | ON                              |

| sql_log_off                             | OFF                             |

| sql_log_update                          | ON                              |

| sync_binlog                             | 0                               |

+-----------------------------------------+---------------------------------+

38 rows in set (0.00 sec)

 

mysql> SHOW MASTER LOGS;

+------------------+-----------+

| Log_name         | File_size |

+------------------+-----------+

| mysql-bin.000001 |       106 |

+------------------+-----------+

1 row in set (0.00 sec)

 

做全量备份,备份所有数据到/root/sqlbak/all.sql文件中

[root@www ~]# mysqldump -uroot --all-databases --lock-all-tables --master-data=2 > /root/sqlbak/all.sql

[root@www ~]# less ./sqlbak/all.sql

 

2、完全备份还原:

[root@www ~]# scp ./sqlbak/all.sql 192.168.88.130:/root/

root@192.168.88.130's password:

all.sql                    100%  524KB 523.6KB/s   00:00

 

备用机上192.168.88.130

[root@test ~]# service mysqld start

正在启动 mysqld [确定]

[root@test ~]# mysql

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| test                 |

+--------------------+

3 rows in set (0.05 sec)

 

mysql> quit

Bye

将完全备份导入

[root@test ~]# mysql < all.sql

[root@test ~]# mysql

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| hellodb             |

| mysql               |

| test                  |

| testdb               |

+--------------------+

5 rows in set (0.00 sec)

 

mysql> use hellodb

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 students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.01 sec)

修改的部分未导入

mysql> quit

Bye

 

四、利用mysqlbinlog做增量备份还原

1、为完全备份后所作的修改做增量备份:--start-position=106

mysql> use hellodb;

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>

#插入数据,有意做修改,演示增量备份

mysql> INSERT INTO students (Name,Age,Gender,ClassID,TeacherID) VALUES ('Cao Cao',15,'M',3,7);

Query OK, 1 row affected (0.01 sec)

 

mysql> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

|    26 | Cao Cao       |  15 | M      |       3 |         7 |

+-------+---------------+-----+--------+---------+-----------+

26 rows in set (0.00 sec)

mysql> DELETE FROM students WHERE StuID=3;

Query OK, 1 row affected (0.01 sec)

mysql> QUIT

Bye

 

#没有输出重定向则默认输出到标准输出

[root@www ~]# mysqlbinlog --start-position=106 /var/lib/mysql/mysql-bin.000001

;

;

DELIMITER ;

# at 4

#171123  0:22:11 server id 1  end_log_pos 106   Start: binlog v 4, server v 5.1.73-log created 171123  0:22:11 at startup

# Warning: this binlog is either in use or was not closed properly.

ROLLBACK;

BINLOG '

......

 

[root@www ~]# mysqlbinlog --start-position=106 /var/lib/mysql/mysql-bin.000001 > incre.sql

利用二进制日志记录还原修改后的记录,做增量备份

结合二进制日志记录做时间点还原

[root@www ~]# ls

apr-1.5.2                    incre.sql            

[root@www ~]# scp incre.sql 192.168.88.130:/root

root@192.168.88.130's password:

incre.sql                          100%  54KB 523.6KB/s   00:00

           

2、还原增量备份

[root@test ~]# ls

all.sql                              incre.sql       

[root@test ~]# mysql < incre.sql

[root@test ~]# mysql

mysql> use hellodb

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 students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

|    26 | Cao Cao       |  15 | M      |       3 |         7 |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.00 sec)

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有