Backups Chap 7
Backups Chap 7
Chapter 7
Table of Contents
Introduction....................................................................................................................................3
Mysqldump......................................................................................................................................3
XtraBackup.....................................................................................................................................5
How to do it….......................................................................................................................................................6
CentOS:....................................................................................................................................................6
Ubuntu:.....................................................................................................................................................6
Locking Instances for Backup.......................................................................................................7
How to do it...........................................................................................................................................................7
Binary Log Backup.........................................................................................................................7
How to do it...........................................................................................................................................................7
Introduction
2 types of backups:
- Logical Backup (Mysqldump)
o Exports all the databases the databases, table structures, data, and stored routines
into a set of SQL statements that can be executed again to recreate the state of the
database
- Physical Backup (XtraBackup)
o Contains all the files on the system that the databases used to store all the
database entities.
Mysqldump
shell> mysqldump [options]
Ignore Tables:
Specific Rows:
XtraBackup
XtraBackup is an open source backup software provided by Percona. It copies flat files
without shutting down the server, but to avoid inconsistencies, it uses a redo log file. It is
widely used by many companies as a standard backup tool. The advantages are that it is
very fast compared to logical backup tools and recovery is also very fast.
This is how Percona XtraBackup works (taken from the Percona XtraBackup
documentation):
1. It copies your InnoDB data files, which results in data that is internally
inconsistent; but then it performs crash recovery on the files to make them a
consistent, usable database again.
2. This works because InnoDB maintains a redo log, also called the transaction log.
This contains a record of every change to the InnoDB data. When InnoDB starts, it
inspects the data files and the transaction log, and performs two steps. It applies
committed transaction log entries to the data files, and it performs an undo
operation on any transactions that modified data but did not commit.
How to do it…
CentOS:
1. Install mysql-community-libs-compat:
4. Install XtraBackup:
Ubuntu:
2. Install the downloaded package with dpkg. To do that, run the following
commands as root or with sudo:
As of MySQL 8, you can lock the instance for backup, which will allow the DML during
online backup and block all the operations that could result in an inconsistent snapshot.
How to do it...
Before you begin your backup, lock the instance for backup:
mysql> LOCK INSTANCE FOR BACKUP;
You know that binary logs are needed for point-in-time recovery. In this section, you will
understand how to take a backup of binary logs. The process streams the binary logs from
the database server to a remote backup server. You can take the binary log backup from
either the slave or the master. If you are taking the binary log backup from the master and
the actual backup from the slave, you should use --dump-slave to get the corresponding
master log position. If you are using mydumper or XtraBackup, it gives both the master and
slave binary log positions.
How to do it...
3. Log in to the backup server and execute the following command. This will copy
the binary logs from the MySQL server to the backup server. You can start using
nohup or disown: