MySQL 备份和恢复(三)Xtrabackup实现热备:完全备份+增量备份
PerconaXtraBackupistheworld’sonlyopen-source,freeMySQLhotbackupsoftwarethatperformsnon-blockingbackupsforInnoDBandXtraDBdatabases.WithPerconaXtraBack
Percona XtraBackup is the world’s only open-source, free MySQL hot backup software that performs non-blocking backups for InnoDB and XtraDB databases. With Percona XtraBackup, you can achieve the following benefits:
以上摘自官方文档对Xtrabackup的描述。
Xtrabackup是Percona公司的开源mysql热备软件,软件自身支持完全备份和增量备份,功能强大,使用简单,且备份结束会自动检查备份的可用性。对于InnoDB和XtraDB可以实现无阻塞的备份。
Xtrabackup会在备份目录下自动生成以当前日期和时间为名的目录,目录下包含当前备份所有数据文件和丰富的当前备份时的状态信息。
实例演示:
xtrabackup的安装,安装包可从官网下载,官方提供了二进制和源码包,根据自己需要下载
/* 下载官方的rpm包安装,xtrabackup要依赖perl-DBD-mysql包,不想手动解决依赖关系可以yum localinstall安装 */ [root@console ~]# yum localinstall --nogpgcheck percona-xtrabackup-2.1.4-656.rhel6.x86_64.rpm -y /* xtrabackup安装后生成的文件不多 */ [root@console ~]# rpm -ql percona-xtrabackup /usr/bin/innobackupex /* 备份时用的命令,会根据mysql版本自动调用xtrabackup_{55,56} */ /usr/bin/innobackupex-1.5.1 /usr/bin/xbcrypt /* 提供备份过程加密支持 */ /usr/bin/xbstream /* 支持流式备份 */ /usr/bin/xtrabackup /usr/bin/xtrabackup_55 / * 这个和下面那个才是备份过程实际调用的备份程序 */ /usr/bin/xtrabackup_56 /usr/share/doc/percona-xtrabackup-2.1.4 /usr/share/doc/percona-xtrabackup-2.1.4/COPYING /* 文档只有一个软件授权文件,没有man文档,不过--help给出的帮助信息也比较丰富 */备份过程:
/* 在库db1中准备一张表tb1,做效果比较用 */ MariaDB [(none)]> CREATE DATABASE db1; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> USE db1 Database changed MariaDB [db1]> CREATE TABLE `tb1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(30) NOT NULL, `Gender` enum('F','M','O') NOT NULL, PRIMARY KEY (`id`) ); Query OK, 0 rows affected (0.22 sec) MariaDB [db1]> DESC tb1; +--------+-------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(30) | NO | | NULL | | | Gender | enum('F','M','O') | NO | | NULL | | +--------+-------------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) MariaDB [db1]> INSERT INTO tb1 (Name,Gender) VALUES ('Tom','M'),('Jerry','F'); Query OK, 2 rows affected (0.05 sec) Records: 2 Duplicates: 0 Warnings: 0 MariaDB [db1]> SELECT * FROM tb1; +----+-------+--------+ | id | Name | Gender | +----+-------+--------+ | 1 | Tom | M | | 2 | Jerry | F | +----+-------+--------+ 2 rows in set (0.00 sec) /* 创建一个用于备份的最小权限的用户 */ MariaDB [(none)]> CREATE USER 'bakuser'@'localhost' IDENTIFIED BY 'backupass'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> REVOKE ALL PRIVILEGES,GRANT OPTION FROM 'bakuser'@'localhost'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'bakuser'@'localhost'; Query OK, 0 rows affected (0.00 sec)现在先做一次完全备份:
/* 全备只需指定用于备份的用户名、密码和备份路径即可,最后出现innobackupex: completed OK! 则代表备份成功 */ [root@node1 ~]# innobackupex --user=bakuser --password=backupass /innobackup/ innobackupex: Backup created in directory '/innobackup/2014-07-31_09-27-36' innobackupex: MySQL binlog position: filename 'mysql-bin.000001', position 1270 140731 09:27:39 innobackupex: Connection to database server closed 140731 09:27:40 innobackupex: completed OK! /* 看一下备份都生成了哪些文件,除了数据库文件外还多了一些文件,注意由于我用root登陆系统,备份后的文件属主属组都是root,恢复后要改为运行mysqld进程的用户,不然mysql起不来 */ [root@node1 ~]# cd /innobackup/2014-07-31_09-27-36/ [root@node1 2014-07-31_09-27-36]# ll total 18476 -rw-r--r--. 1 root root 260 Jul 31 09:27 backup-my.cnf /* 备份命令用到的配置选项信息 */ drwx------. 2 root root 4096 Jul 31 09:27 db1 drwx------. 2 root root 4096 Jul 31 09:27 hellodb -rw-r-----. 1 root root 18874368 Jul 31 09:27 ibdata1 drwx------. 2 root root 4096 Jul 31 09:27 mydb drwxr-xr-x. 2 root root 4096 Jul 31 09:27 mysql drwxr-xr-x. 2 root root 4096 Jul 31 09:27 performance_schema drwxr-xr-x. 2 root root 4096 Jul 31 09:27 test -rw-r--r--. 1 root root 13 Jul 31 09:27 xtrabackup_binary /* 记录备份过程实际用的备份程序 */ -rw-r--r--. 1 root root 24 Jul 31 09:27 xtrabackup_binlog_info /* 记录备份时的二进制日志文件和当前的位置 */ -rw-r-----. 1 root root 89 Jul 31 09:27 xtrabackup_checkpoints /* 记录备份类型、 状态(是否prepared)、是否压缩、备份的LSN(Log Serial Number日志序列号)范围等信息 */ -rw-r-----. 1 root root 2560 Jul 31 09:27 xtrabackup_logfile /* xtrabackup自己的日志文件,新版本中不直接可见 */ [root@node1 2014-07-31_09-27-36]# cat backup-my.cnf # This MySQL options file was generated by innobackupex. # The MySQL server [mysqld] innodb_data_file_path=ibdata1:10M:autoextend innodb_log_files_in_group=2 innodb_log_file_size=5242880 innodb_fast_checksum=0 innodb_page_size=16384 innodb_log_block_size=512 [root@node1 2014-07-31_09-27-36]# cat xtrabackup_binary xtrabackup_55[root@node1 2014-07-31_09-27-36]# [root@node1 2014-07-31_09-27-36]# cat xtrabackup_binlog_info mysql-bin.000001 1270 [root@node1 2014-07-31_09-27-36]# cat xtrabackup_checkpoints backup_type = full-backuped from_lsn = 0 to_lsn = 1660869 last_lsn = 1660869 compact = 0 [root@node1 2014-07-31_09-27-36]# file xtrabackup_logfile xtrabackup_logfile: data
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

How to connect to MySQL using phpMyAdmin? The URL to access phpMyAdmin is usually http://localhost/phpmyadmin or http://[your server IP address]/phpmyadmin. Enter your MySQL username and password. Select the database you want to connect to. Click the "Connection" button to establish a connection.
