Skip to main content

Backup Data using Percona XtraBackup

In the earlier post we discuss about how to take backup using mysqldump. Today will discuss about how to take backup using Percona XtraBackup. The Percona XtraBackup is a Physical Dump / Backup which consists of raw copies of data and data directories present in it. This type of backup is very useful and suitable for the databases which contains large and important data sets that need to recovered quickly when the disaster occurs.

Creating a Backup:

To create a backup, Xtrabackup script has to be called with backup, datadir and targetdir parameters.
backup - is to create the backup
datadir - which is where the MySQL data directory stored
targetdir - backup directory, where we want to save the backup

If the target directory does not exist, xtrabackup creates it. If the directory does exist and is empty, xtrabackup will succeed. xtrabackup will not overwrite existing files, it will fail with operating system error 17, file exists.

The tool changes its working directory to the data directory and performs two primary tasks to complete the backup:
  • It starts a log-copying thread in the background. This thread watches the InnoDB log files, and when they change, it copies the changed blocks to a file called xtrabackup_logfile in the backup target directory. This is necessary because the backup might take a long time, and the recovery process needs all of the log file entries from the beginning to the end of the backup.
  • It copies the InnoDB data files to the target directory. This is not a simple file copy; it opens and reads the files similarly to the way InnoDB does, by reading the data dictionary and copying them a page at a time.

$ xtrabackup --backup --datadir=/var/lib/mysql/ --target-dir=/data/backups/mysql/

Sample output:


log scanned up to (3646475517369)
log scanned up to (3646475581716)
log scanned up to (3646475636841)
log scanned up to (3646475718082)
log scanned up to (3646475988095)
log scanned up to (3646476048286)
log scanned up to (3646476102877)
 log scanned up to (3646476140854)
[01] Copying /usr/local/mysql/var/ibdata1  

to /usr/local/mysql/Backups/2017-01-01_21-11-15/ibdata1

[01]        ...done


After the backup is finished, the target directory will contain files such as the following, assuming you have a single InnoDB table test.tbl1 if MySQL’s innodb_file_per_table option is enabled.

/data/backups/mysql/ibdata1
/data/backups/mysql/test
/data/backups/mysql/test/tbl1.ibd
/data/backups/mysql/xtrabackup_checkpoints
/data/backups/mysql/xtrabackup_logfile


Note: The backup time will purely depend on your Size of Database you have.

Comments

Popular posts from this blog

Warning: Using a password on the command line interface can be insecure

We usually use MySQL login information on shell scripts to load some data into database or to fetch some monitoring information. To login to the database will write login information on Shell Scripts as below #!/bin/sh username = someusername password = somepassword $ mysql -u$username -p$password -A -v -S By doing that so, we will hit a warning in stdout saying: Warning: Using a password on the command line interface can be insecure To avoid the warning in shell script, we need to so some workaround like below: 1. Create a hidden file configuration file > touch /tmp/.mysqllogin.cnf 2. Enter your database credential information on the hidden file: > vi /tmp/.mysqllogin.cnf [client] user=someusername password=somepassword 3. Save the file and try to login to mysql using  --defaults-extra-file  keyword like $ mysql --defaults-extra-file=/tmp/.mysqllogin.cnf -A -v By using this workaround you can avoid the warning.

Unable to open the log file (mysqld)

While starting the server you may find the below errors sometimes, it's because of unintentionally deleting the MySQL Binary Log files. When starting mysql if the server unable to find the mysql-bin-log files then below errors will arise. 170418 12:15:19 InnoDB: 5.5.30 started; log sequence number 32347593422 /usr/sbin/mysqld: File './mysql-bin.000023' not found (Errcode: 2) 170418 12:15:19 [ERROR] Failed to open log (file './mysql-bin.000023', errno 2) 170418 12:15:19 [ERROR] Could not open log file 170418 12:15:19 [ERROR] Can't init tc log 170418 12:15:19 [ERROR] Aborting 170418 12:15:19 InnoDB: Starting shutdown... 170418 12:15:20 InnoDB: Shutdown completed; log sequence number 32347593422 170418 12:15:20 [Note] /usr/sbin/mysqld: Shutdown complete Do we have a solution to get rid of this and start MySQL again? Well, we have two types of workarounds to start MySQL again. 1. Deleting the missed files in binlog .index  file 2. Disabling the binlog log

Monitoring MySQL with Percona Monitoring and Management

In this blog post we will see how to monitor MySQL databases using the open source monitoring tool provided by Percona, referred as Percona Monitoring and Management (PMM). About PMM: Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL and MongoDB performance. It is developed by Percona in collaboration with experts in the field of managed database services, support and consulting. PMM is a free and open-source solution that you can run in your own environment for maximum security and reliability. It provides thorough time-based analysis for MySQL and MongoDB servers to ensure that your data works as efficiently as possible. Basic Requirements: 1. Need at least one Linux server to install PMM Client and PMM Server. 2. Need Operating System - root user credentials 3. Default port's(80) have to be open if using to or more servers. 4. A MySQL user is required to capture the Queries in the Database. 5. A Docker se