如何使用mysqldump/xtrabackup备份

Mariadb备份

  • 本文主要详细说明Mariadb如何使用mysqldump和Xtrabackup备份mysql数据库
  • mysqldump实现如下功能:

1、对hellodb数据库进行增删后还原hellodb数据库;
2、由还原后的hellodb收据库再还原至增删后的hellodb收据库;

msyqldump备份及还原

mysqldump备份数据库
[[email protected] ~]# mysqldump --databases hellodb --single-transaction -R --triggers -E --master-data=2 --flush-logs > /tmp/hellodb-$(date +%F)
  • 数据库操作如下:

删除stuid=25,增加stuid=88,然后删除数据库同时备份二进制日志;

[[email protected] ~]# mysqlWelcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 5.5.44-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> use students;
ERROR 1049 (42000): Unknown database ‘students‘
MariaDB [(none)]> 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
MariaDB [hellodb]> 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.00 sec)

MariaDB [hellodb]> delete from students where stuid=25;
Query OK, 1 row affected (0.00 sec)

MariaDB [hellodb]> 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 |
+-------+---------------+-----+--------+---------+-----------+
24 rows in set (0.00 sec)

MariaDB [hellodb]> insert into students values (‘88‘,‘tangceng‘,‘88‘,‘M‘,‘3‘,‘7‘);
Query OK, 1 row affected (0.00 sec)

MariaDB [hellodb]> 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 |
|    88 | tangceng      |  88 | M      |       3 |         7 |
+-------+---------------+-----+--------+---------+-----------+
25 rows in set (0.00 sec)

MariaDB [hellodb]> drop database hellodb;
Query OK, 7 rows affected (0.04 sec)

MariaDB [hellodb]> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000007 |      670 |              |                  |
+-------------------+----------+--------------+------------------+
  • 使用mysqlbinlog命令查看日志文件master-log.000007 ;

[[email protected] ~]# mysqlbinlog /var/lib/mysql/master-log.000007

/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;/*!40019 SET @@session.max_insert_delayed_threads=0*/;/*!50003 SET @[email protected]@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#170221  8:56:27 server id 1  end_log_pos 245 	Start: binlog v 4, server v 5.5.44-MariaDB-log created 170221  8:56:27# Warning: this binlog is either in use or was not closed properly.BINLOG ‘
O5CrWA8BAAAA8QAAAPUAAAABAAQANS41LjQ0LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAsXMXYw==
‘/*!*/;# at 245
#170221  8:59:58 server id 1  end_log_pos 316 	Query	thread_id=20	exec_time=0	error_code=0SET TIMESTAMP=1487638798/*!*/;SET @@session.pseudo_thread_id=20/*!*/;SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;SET @@session.sql_mode=0/*!*/;SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;/*!\C utf8 *//*!*/;SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;SET @@session.lc_time_names=0/*!*/;SET @@session.collation_database=DEFAULT/*!*/;BEGIN/*!*/;# at 316
#170221  8:59:58 server id 1  end_log_pos 417 	Query	thread_id=20	exec_time=0	error_code=0use `hellodb`/*!*/;SET TIMESTAMP=1487638798/*!*/;delete from students where stuid=25/*!*/;# at 417
#170221  8:59:58 server id 1  end_log_pos 444 	Xid = 913COMMIT/*!*/;# at 444
#170221  9:04:49 server id 1  end_log_pos 515 	Query	thread_id=20	exec_time=0	error_code=0SET TIMESTAMP=1487639089/*!*/;BEGIN/*!*/;# at 515
#170221  9:04:49 server id 1  end_log_pos 643 	Query	thread_id=20	exec_time=0	error_code=0SET TIMESTAMP=1487639089/*!*/;insert into students values (‘88‘,‘tangceng‘,‘88‘,‘M‘,‘3‘,‘7‘)/*!*/;# at 643
#170221  9:04:49 server id 1  end_log_pos 670 	Xid = 921COMMIT/*!*/;# at 670
#170221  9:15:08 server id 1  end_log_pos 757 	Query	thread_id=20	exec_time=0	error_code=0SET TIMESTAMP=1487639708/*!*/;drop database hellodb/*!*/;DELIMITER ;
# End of log fileROLLBACK /* added by mysqlbinlog */;/*!50003 SET [email protected]_COMPLETION_TYPE*/;/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
  • 可以看到在位置670为删除数据库,所以备份670位置之前的二进制文件;

[[email protected] ~]#mysqlbinlog --stop-position=670 /var/lib/mysql/master-log.000007 > /tmp/bin.log

注意在备份的时候需要关闭二进制日志,避免将备份的步骤添加至二进制文件 MariaDB [(none)]> set @@session.sql_log_bin=OFF;

mysqldump还原数据库
  • 还原1

MariaDB [(none)]> source /tmp/hellodb-2017-02-21;

  • 如下已完成数据库恢复至最初的数据;
MariaDB [hellodb]> 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.00 sec)
  • 还原2

MariaDB [(none)]> source /tmp/bin.log

  • 还原数据如下已还原至更改过得表信息:
MariaDB [hellodb]> 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 |
|    88 | tangceng      |  88 | M      |       3 |         7 |
+-------+---------------+-----+--------+---------+-----------+
25 rows in set (0.00 sec)

还原完成后开启MariaDB [(none)]> set @@session.sql_log_bin=ON;

使用Xtrabackup进行备份还原

使用Xtrabackup对当前数据库进行备份

安装percona-xtrabackup-2.3.2-1.el7.x86_64.rpm软件
创建备份目录并备份数据库

[[email protected] ~]# mkdir -p /data/backup[[email protected] ~]# innobackupex --user=root --host=localhost /data/backupxtrabackup: Transaction log of lsn (1756943) to (1756943) was copied.170221 14:01:41 completed OK!
[[email protected] mysql]# ll /data/backup/2017-01-19_10-40-32/
total 118804-rw-r----- 1 root root      385 Jan 19 10:41 backup-my.cnfdrwx------ 2 root root      138 Jan 19 10:41 hellodb-rw-r----- 1 root root 18874368 Jan 19 10:43 ibdata1-rw-r--r-- 1 root root 50331648 Jan 19 10:43 ib_logfile0-rw-r--r-- 1 root root 50331648 Jan 19 10:43 ib_logfile1drwx------ 2 root root     4096 Jan 19 10:41 mysqldrwx------ 2 root root     4096 Jan 19 10:41 performance_schemadrwx------ 2 root root       19 Jan 19 10:41 test-rw-r----- 1 root root      113 Jan 19 10:43 xtrabackup_checkpoints-rw-r----- 1 root root      438 Jan 19 10:41 xtrabackup_info-rw-r----- 1 root root  2097152 Jan 19 10:43 xtrabackup_logfile[[email protected] mysql]# vim /etc/my.conf.d/server.conf
innodb_log_file_size = 50331648
使用Xtrabackup对当前数据库进行还原

[[email protected] mysql]# innobackupex --apply-log /data/backup/2017-01-19_10-40-32/ [[email protected] mysql]# innobackupex --copy-back /data/backup/2017-01-19_10-40-32/ [[email protected] mysql]# chown -R mysql.mysql ./* [[email protected] mysql]# systemctl start mariadb

使用Xtrabackup对当前数据库进行增量备份
  • 第一次备份

[[email protected] ~]# innobackupex --user=root --host=localhost /data/backup/

170119 14:50:49 [00]        ...done
xtrabackup: Transaction log of lsn (1680362) to (1680362) was copied.
170119 14:50:49 completed OK!
[[email protected] ~]# ll /data/backup/
total 4drwx------ 5 root root 4096 Jan 19 14:50 2017-01-19_14-50-46[[email protected] ~]# cat /data/backup/2017-01-19_14-50-46/xtrabackup_checkpoints 
backup_type = full-backuped
from_lsn = 0to_lsn = 1680362last_lsn = 1680362compact = 0recover_binlog_info = 0[[email protected] ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;+--------------------+| Database           |
+--------------------+| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+4 rows in set (0.12 sec)

MariaDB [(none)]>
  • 在数据库中增加hellodb数据库
[[email protected] ~]# mysql < hellodb.sql [[email protected] ~]# msyql-bash: msyql: command not found
[[email protected] ~]# mysqlWelcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 29Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+| Database           |
+--------------------+| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+5 rows in set (0.00 sec)

MariaDB [(none)]>
  • 第一次增量备份

[[email protected] ~]# innobackupex --incremental --user=root --host=localhost /data/backup/ --incremental-basedir=/data/backup/2017-01-19_14-50-46/

[[email protected] ~]# ll /data/backup/total 8drwx------ 5 root root 4096 Jan 19 14:50 2017-01-19_14-50-46drwx------ 6 root root 4096 Jan 19 14:56 2017-01-19_14-56-12[[email protected] ~]# cat /data/backup/2017-01-19_14-56-12/xtrabackup_checkpoints backup_type = incremental
from_lsn = 1680362to_lsn = 1708884last_lsn = 1708884compact = 0recover_binlog_info = 0[[email protected] ~]#
  • 在hellodb数据库中增加haha表;
[[email protected] ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 5.5.44-MariaDB MariaDB ServerCopyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> ls
    -> ;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘ls‘ at line 1
MariaDB [(none)]> 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
MariaDB [hellodb]> create table haha(id int,name char(100));Query OK, 0 rows affected (0.01 sec)

MariaDB [hellodb]>
  • 进行第二次增量备份

[[email protected] ~]# innobackupex --incremental --user=root --host=localhost /data/backup/ --incremental-basedir=/data/backup/2017-01-19_14-56-12/

[[email protected] ~]# ll /data/backup/total 12drwx------ 5 root root 4096 Jan 19 14:50 2017-01-19_14-50-46drwx------ 6 root root 4096 Jan 19 14:56 2017-01-19_14-56-12drwx------ 6 root root 4096 Jan 19 15:02 2017-01-19_15-02-14[[email protected] ~]# cat /data/backup/2017-01-19_15-02-14/xtrabackup_checkpoints backup_type = incremental
from_lsn = 1708884to_lsn = 1711375last_lsn = 1711375compact = 0recover_binlog_info = 0[[email protected] ~]#

*差异备份

[[email protected] ~]# innobackupex --incremental --user=root --host=localhost /data/backup/ --incremental-basedir=/data/backup/2017-01-19_14-50-46/

[[email protected] ~]# ll /data/backup/total 16drwx------ 5 root root 4096 Jan 19 14:50 2017-01-19_14-50-46drwx------ 6 root root 4096 Jan 19 14:56 2017-01-19_14-56-12drwx------ 6 root root 4096 Jan 19 15:02 2017-01-19_15-02-14drwx------ 6 root root 4096 Jan 19 15:06 2017-01-19_15-06-29[[email protected] ~]# cat /data/backup/2017-01-19_15-06-29/xtrabackup_checkpoints backup_type = incremental
from_lsn = 1680362to_lsn = 1711375last_lsn = 1711375compact = 0recover_binlog_info = 0[[email protected] ~]#
增量还原
  • 将数据还原至新的一台服务器上

[[email protected] ~]# innobackupex --apply-log --redo-only /data/backup/2017-01-19_14-50-46/

  • 添加第一个增量

innobackupex --apply-log --redo-only /data/backup/2017-01-19_14-50-46/ --incremental-dir=/data/backup/2017-01-19_14-56-12/

  • 添加第二个增量

[[email protected] ~]# innobackupex --apply-log --redo-only /data/backup/2017-01-19_14-50-46/ --incremental-dir=/data/backup/2017-01-19_15-02-14/

  • 执行还原命令:

[[email protected] mysql]# innobackupex --copy-back /data/backup/2017-01-19_14-50-46/

  • 更改/var/lib/mysql/文件的属主及属组

[[email protected] mysql]# chown -R mysql.mysql ./*

  • 启动mysql

[[email protected] mysql]# systemctl start mariadb

  • 查看还原信息
[[email protected] mysql]# mysqlWelcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;
+------------------------------+
| Database                     |
+------------------------------+
| information_schema           |
| #mysql50#2017-01-19_15-22-30 |
| hellodb                      |
| mysql                        |
| performance_schema           |
| test                         |
+------------------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use databases;
ERROR 1049 (42000): Unknown database ‘databases‘
MariaDB [(none)]> 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
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes           |
| coc               |
| courses           |
| haha              |
| scores            |
| students          |
| teachers          |
| toc               |
+-------------------+
8 rows in set (0.01 sec)

MariaDB [hellodb]> quit
Bye
[[email protected] mysql]#
时间: 2024-08-03 15:30:51

如何使用mysqldump/xtrabackup备份的相关文章

MySQL备份与恢复常用方法总结(mysqldump/xtrabackup/lvm快照备份/二进制日志及时点恢复)

MySQL备份与恢复常用方法总结 (mysqldump/xtrabackup/lvm快照备份/逻辑备份与恢复/二进制日志及时点恢复) 自言:学习在于总结,把所了解的类似东西放到一起更能加深记忆 一.了解备份相关知识 1)按服务器备份时状态可分为:     热备份:读.写不受影响:     温备份:仅可以执行读操作:     冷备份:离线备份:读.写操作均中止:2)按服务器备份数据集可分为:     物理备份:复制数据文件:     逻辑备份:将数据导出至文本文件中:3)按服务器备份数据量可分为:

mysqldump和xtrabackup备份原理实现说明

背景: MySQL数据库备份分为逻辑备份和物理备份两大类,犹豫到底用那种备份方式的时候先了解下它们的差异: 逻辑备份的特点是:直接生成SQL语句,在恢复的时候执行备份的SQL语句实现数据库数据的重现. 物理备份的特点是:拷贝相关数据文件. 这二种备份差异 :逻辑备份其备份.还原慢,但备份文件占用的空间小:物理备份其备份还原快,备份文件占用空间大. 到底选择那种备份方式,具体根据自己的实际情况,如需要的是热备还是冷备?数据量大不大?磁盘空间够不够等因素决定. 逻辑备份工具主要有:mysqldump

mysqldump xtrabackup 逻辑备份和物理备份

逻辑备份 逻辑备份是备份sql语句,在恢复的时候执行备份的sql语句实现数据库数据的重现. 工具:mysqldump 特点: 1.可移植性比较强 2.备份和恢复的花费时间长,不适用于大型业务系统 物理备份 物理备份就是备份数据文件了,比较形象点就是cp下数据文件,但真正备份的时候自然不是的cp这么简单. 工具:xtrabackup 特点: 1.不具备移植性,备份环境和恢复环境必须是完全相同的 2.备份和恢复时间较快,适用于大型业务系统 mysqldump 备份原理:通过协议连接到mysql数据库

Percona Xtrabackup备份mysql(转)

原文:http://www.drupal001.com/2014/02/percona-xtrabackup-mysql/ Xtrabackup简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁).XtraBackup支持所有的Percona Server.MySQL.MariaDB和Drizzle. XtraBackup优势 : 1.无需停止数据库进行InnoDB热

Percona Xtrabackup 备份MySQL 实例(转)

老规矩,开场白,刚开始用mysqldump,备份100G+的数据库,再加上服务器繁忙,备份速度像蜗牛似的,于是寻找更高效的备份方法.网上都说用xtrabackup比较适合备份大的数据库,而且备份效率也高,就尝试使用一次,结果明显感觉比mysqldump备份与恢复速度就是快不少,那以后就用它了.大礼拜日的在家也没事,结合生产环境,写了这篇文档,刚接触的朋友,可以参考下,不多说,入正题! 1.初次备份前准备工作 1.1 了解备份方式 热备份:读写不受影响(mysqldump-->innodb) 温备

xtrabackup备份恢复测试 -转

Chinaunix首页 | 论坛 | 认证专区 | 博客 登录 | 注册 博文      博主 王恒-Henryhengwang.blog.chinaunix.net 我的项目:https://github.com/HengWang/ ChinaUnix博客技术文章推荐标准和规范 有奖征集:文集--博客系列博文管理 CU博客频道6月技术图书有奖试读活动 首页 | 博文目录 | 关于我 king_wangheng 博客访问: 486455 博文数量: 117 博客积分: 1715 博客等级: 上尉

xtrabackup备份还原MySQL数据库

原文:xtrabackup备份还原MySQL数据库 mysqldump 备份鉴于其自身的某些特性(锁表,本质上备份出来insert脚本或者文本,不支持差异备份),不太适合对实时性要求比较高的情况Xtrabackup可以解决mysqldump存在的上述的一些问题,生产环境应用的也会更多一些.本文简单测试一下Xtrabackup对MySQL数据库的备份还原操作. 本着先把功能先撸起来再深入细节的原则,粗略地实现了一个备份还原,并未深入细节. 网上有不少xtrabackup的文章,因为环境不一样,有些

innobackupex xtrabackup 备份恢复mysql数据

复制地址:https://www.linuxyw.com/download/xtrabackup.pdf http://www.linuxyw.com Email:[email protected] xtrabackup 对 MySQL 数据库的备份及恢复 此文档,只是简单地研究了下,用于数据库全备和增备,效果不错 因为目前对此软件未有需求,所以,文档并不完善,等有时间了,再进行完善吧 此文档资料,互联网收集而成 本人博客: http://www.linuxyw.com xtrabackup x

mysqldump 定时备份数据(全量)

MYSQL 数据库备份有很多种(cp.tar.lvm2.mysqldump.xtarbackup)等等,具体使用哪一个还要看你的数据规模.下面给出一个表 #摘自<学会用各种姿态备份Mysql数据库> 备份方法 备份速度 恢复速度 便捷性 功能 一般用于 cp 快 快 一般.灵活性低 很弱 少量数据备份 mysqldump 慢 慢 一般.可无视存储引擎的差异 一般 中小型数据量的备份 lvm2 快 快 一般.支持几乎热备.速度快 一般 中小型数据量的备份 xtrabackup 较快 较快 实现i