MariaDB恢复备份杂记(2)

Mariadb备份恢复

杂项

1、mariadb默认引擎其实xtradb

MariaDB [(none)]> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |

XtraBackup

1、安装XtraBackup

yum install percona-xtrabackup-2.3.2-1.el7.x86_64.rpm -y

1.1 查看安装生成的文件

[[email protected] ~]# rpm -ql percona-xtrabackup
/usr/bin/innobackupex
/usr/bin/xbcloud
/usr/bin/xbcloud_osenv
/usr/bin/xbcrypt
/usr/bin/xbstream
/usr/bin/xtrabackup
/usr/share/doc/percona-xtrabackup-2.3.2
/usr/share/doc/percona-xtrabackup-2.3.2/COPYING
/usr/share/man/man1/innobackupex.1.gz
/usr/share/man/man1/xbcrypt.1.gz
/usr/share/man/man1/xbstream.1.gz

/usr/share/man/man1/xtrabackup.1.gz

1.2 准备工作

1.2.1 确保所有表都是InnoDB

1.2.2 确认一个参数,该参数实现很多高级功能(单独的表空间功能)
MariaDB [hellodb]> SHOW GLOBAL VARIABLES LIKE ‘innodb%‘;
| innodb_file_per_table                     | OFF

1.2.3 因为已经有数据库了。需要删除多有数据库,开启参数,重新生成;
[[email protected] ~]# rm -rf /data/mysql/*
[[email protected] ~]# rm -rf /data/binlogs/*
[[email protected] ~]# vim /etc/my.cnf

innodb_file_per_table=ON

[[email protected] ~]# systemctl start mariadb.service

1.2.4 还原数据库
[[email protected] ~]# mysql < all.sql
MariaDB [hellodb]> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |     30349 |
| mysql-bin.000002 |   1038814 |
| mysql-bin.000003 |    522279 |

2、备份

2.1 创建备份目录

[[email protected] ~]# mkdir /backups/

2.2 备份

2.1 全数据库备份
[[email protected] ~]# innobackupex --user=root /backups/

2.2 将数据库恢复至master1
2.2.1 master1准备:
[[email protected] data]# mkdir -pv /data/mysql
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysql’
[[email protected] data]# chown mysql.mysql /data/mysql/
[[email protected] data]# service mysqld start
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

2.2.2 恢复备份
拷贝数据库倒要恢复的机子:
[[email protected] ~]# scp /backups/2017-01-28_03-19-23/* [email protected]:/tmp/backups

目录整理:
[[email protected] ~]# innobackupex --apply-log /backups/2017-01-28_03-19-23/

恢复备份:
[[email protected] ~]# service mysqld stop
[[email protected] ~]# rm -rf /data/mysql/*
[[email protected] ~]# innobackupex --copy-back /backups/2017-01-28_03-19-23/

[[email protected] mysql]# chown -R mysql:mysql /data/mysql/*
[[email protected] mysql]# rm -rf ib_logfile*
[[email protected] mysql]# service mysqld start

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |

3、增量备份

3.1 准备

创建表:
MariaDB [hellodb]> CREATE TABLE testtb (id int);

插入数据:
MariaDB [hellodb]> INSERT INTO testtb VALUES (1),(10),(99);

MariaDB [hellodb]> SELECT * FROM testtb;
+------+
| id   |
+------+
|    1 |
|   10 |
|   99 |
+------+

3.2 重新做完全备份

删除之前的备份
[[email protected] ~]# rm -rf /backups/*

完全备份
[[email protected] ~]# innobackupex /backups/

查看备份类型:
[[email protected] ~]# cat /backups/2017-01-28_05-05-39/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 1645521
last_lsn = 1645521
compact = 0
recover_binlog_info = 0

3.3 数据修改,准备实验增量备份

删除表:
MariaDB [hellodb]> DROP TABLE coc;

MariaDB [hellodb]> INSERT INTO testtb VALUES (44),(32);
插入数据

3.4 增量备份

innobackupex --incremental /backups/ --incremental-basedir=/backups/2017-01-28_05-05-39

[[email protected] ~]# cat /backups/2017-01-28_08-02-15/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 1645521
to_lsn = 1647443
last_lsn = 1647443
compact = 0
recover_binlog_info = 0

3.5 备份还原

停止数据库

3.5.1 整理完全备份
[[email protected] ~]# innobackupex --apply-log --redo-only /backups/2017-01-28_05-05-39/

3.5.2 整理增量备份
[[email protected]ter1 ~]# innobackupex --apply-log --redo-only /backups/2017-01-28_05-05-39/ --incremental-dir=/backups/2017-01-28_08-02-15/

3.5.3 删除数据
[[email protected] ~]# rm -rf /data/mysql/*

3.5.4 恢复备份
[[email protected] ~]# innobackupex --copy-back /backups/2017-01-28_05-05-39/

3.5.5 更改权限
[[email protected] mysql]# chown -R mysql.mysql ./*

3.5.6 启动数据库
MariaDB [hellodb]> SELECT * FROM testtb;
+------+
| id   |
+------+
|    1 |
|   10 |
|   99 |
|   44 |
|   32 |

4、备份单张表

原文地址:http://blog.51cto.com/zhongle21/2087507

时间: 2024-10-03 20:44:08

MariaDB恢复备份杂记(2)的相关文章

使用mysqldump进行mariadb的备份

mysqldump备份介绍 mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等,适用于备份数据量不大的数据库. 优点:备份简单,恢复容易. 备份缺点:schema和数据存储在一起,巨大的SQL语句.单个巨大的备份文件(备份的库和表都在一个文件中). mysqldump: 是一个mysql客户端命令,通过mysql协议连接至mysqld,实现数据库备份 命令的语法格式: mysqldum

初接触Linux,使用Xtrabackuo给Mysql(MariaDB)备份

今天给大家带来的是Xtrabackup给mysql(mariaDB)备份 一.Xtrabackup 1.Xtrabackup介绍 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具 2.Xtrabackup的特点 (1)在线热备整个库的InnoDB.XtraDB表 (2)备份过程不会打断正在执行的事务: (3)在xtra

MySQL恢复备份读书笔记

1. 任何执行时间长于 wait_timeout或interactive_timeout选项值得备份,都会导致会话被关闭,这也会隐含执行UNLOCK TABLES命令.2. 对于使用FLUSH TABLES WITH READ LOCK的备份策略来讲,一个共同的缺陷是它们需要两个独立的线程来完成备份过程.运行FLUSH TABLES WITH READ LOCK命令, 然后从当前连接退出将自动执行一条UNLOCK TABLES命令.从FLUSH TABLES WITH READ LOCK成功返回

官方文档 恢复备份指南三 Recovery Manager Architecture

本节讨论以下问题: About the RMAN Environment                        关于RMAN环境 RMAN Command-Line Client                            RMAN命令行 RMAN Channels                                                      RMAN通道 RMAN Repository                                

官方文档 恢复备份指南七 Using Flashback Database and Restore Points

本章内容: Understanding Flashback Database, Restore Points and Guaranteed Restore Points Logging for Flashback Database and Guaranteed Restore Points Prerequisites for Flashback Database and Guaranteed Restore Points Using Normal and Guaranteed Restore P

官方文档 恢复备份指南六 Configuring the RMAN Environment: Advanced Topics

RMAN高级设置. 本章内容: Configuring Advanced Channel Options  高级通道选项 Configuring Advanced Backup Options 高级备份选项 Configuring Auxiliary Instance Data File Names 配置辅助实例文件名 Configuring the Snapshot Control File Location 配置控制文件快照 Configuring RMAN for Use with a S

官方文档 恢复备份指南二 Getting Started with RMAN

本章对RMAN进行基本的熟悉和了解 1.Overview of the RMAN Environment RMAN运行时需要的最小环境: target database          :RMAN用target命令连接的数据库,在该数据库上执行备份和恢复操作,并备份信息(RMAN reposity 资源库)记录在target数据库的控制文件中. RMAN client              :rman客户端,即RMAN可执行程序.在$ORACLE_HOME/bin下 RMAN运行时可能需要

ubuntu(linux)新装系统恢复备份后无法进入系统问题的解决

1. 引子: 可以跳过直接看3.~5. 我们可能会遇到这样的状况,从ubuntu转到别的系统,兜兜转转又回到了ubuntu. 比如说: Fedora升级后一大堆BUG,与java有关的软件渲染都糟糕的一逼; linux mint 吹上天的 Cinnamon 其实没有综合搜索,反应特别迟钝,每个软件(包括shell)都要2秒后出现; centos和debian这种固若金汤的系统要啥没啥只剩稳定; openSUSE的软件特别少,https://software.opensuse.org/find 又

模拟电话簿系统,新增功能:备份数据和恢复备份

在原来的系统之上增加了两个新的功能,备份数据和恢复备份: 下面是两个功能的具体实现方法: public void saveall() // 备份所有数据 { List<Person> list1 = new ArrayList(); try { // 加载数据库驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); // 获取与数据库的连接 Connection conn = DriverManager.getConnect