Restore the backup¶
The following steps describe how to restore your backup to another Percona Server container and check whether the data is available.
-
Create another Docker volume
$ docker volume create myvol2Expected output
myvol2 -
Run another Percona Server container to restore the backup to
Option Description --nameProvides a name to the container. If you do not use this option, Docker adds a random name. -dDetaches the container. The container runs in the background. -eAdds an environmental variable. This example adds the MYSQL_ROOT_PASSWORDenvironment variable. The instance refuses to initialize if no environmental variable is added. Choose a more secure password, if needed.myvol2Indicates the persistent storage for the database. 8.4Use this tag to specify a specific version. You must provide at least one environment variable to access the database, such as
MYSQL_ROOT_PASSWORD,MYSQL_DATABASE,MYSQL_USER, andMYSQL_PASSWORDor the instance refuses to initialize.For this document, we are using the
8.4tag. In Docker, a tag is a label assigned to an image. Tags are used to maintain different versions of an image. If we did not add a tag, Docker useslatestas the default tag and downloads the latest image from [percona/percona-server on the Docker Hub].To use a Docker volume for persistent storage with a database, specify the path where the database stores its data inside the container, usually
/var/lib/mysql.-
Run a Docker container example
$ docker run -d -p 3307:3306 --name psmysql2 -e MYSQL_ROOT_PASSWORD=secret -v myvol2:/var/lib/mysql percona/percona-server:8.4
Expected output
4501d5524461b4483d414bd218d49ed4f47599add7d7fb81e157951a7a52f3d1 -
-
Stop
psmysql2container$ docker stop psmysql2Expected output
psmysql2 -
Remove all created files in
myvol2to allow xtrabackup restore data tomyvol2The
--rmoption automatically removes the temporary container created from percona/percona-xtrabackup:8.0.34 image after the container exits.$ docker run --volumes-from psmysql2 -v backupvol:/backup_84 -it --rm --user root percona/percona-xtrabackup:8.4 /bin/bash -c "rm -rf /var/lib/mysql/*"If the command executes successfully, the expected output is empty.
-
Restore backup of
psmysqlfrombackupvolto a newpsmysql2instance.$ docker run --platform linux/amd64 --volumes-from psmysql2 -v backupvol:/backup_84 -it --rm --user root percona/percona-xtrabackup:8.4 /bin/bash -c "xtrabackup --copy-back --datadir=/var/lib/mysql/ --target-dir=/backup_84"Expected output
2024-10-07T14:08:59.127166-00:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/var/lib/mysql/ 2024-10-07T14:08:59.128951-00:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --copy-back=1 --target-dir=/backup_84 xtrabackup version 8.4.0-1 based on MySQL server 8.4.0 Linux (x86_64) (revision id: 3792f907) 2024-10-07T14:08:59.129407-00:00 0 [Note] [MY-011825] [Xtrabackup] cd to /backup_84/ ... 2024-10-07T14:08:59.129407-00:00 0 1 [Note] [MY-011825] [Xtrabackup] Done: Copying ./ibtmp1 to /var/lib/mysql/ibtmp1 2024-10-07T14:08:59.129407-00:00 0 [Note] [MY-011825] [Xtrabackup] completed OK!This command restores the backup files from the
backup_8034volume to thepsmysql2container. It uses thepercona/percona-xtrabackup:8.0.34image to run a temporary container with root privileges. It executes the xtrabackup tool with the--copy-backoption, which copies the files from thebackup_8034volume to the /var/lib/mysql/directory in thepsmysql2container. The command uses –rm option to delete the temporary container after it exits.
Validate the backup¶
This section describes the backup validation steps assuming that you backed up mydb database with the employees table as we have in our example. The validation steps may vary depending on your data set.
-
Change the owner of the files in
myvol2fromroottomysqlTo avoid permission issues when running
psmysql2container, you need to change the owner because the files were restored byrootuser andpsmysql2will usemysqluser.$ docker run --volumes-from psmysql2 -v backupvol:/backup_84 -it --rm --user root percona/percona-xtrabackup:8.4 /bin/bash -c "chown -R mysql:mysql /var/lib/mysql/"If the command executes successfully, the expected output is empty.
-
Start the
psmysql2container$ docker start psmysql2Expected output
psmysql2 -
Connect to the database instance.
For this example, we have the following options:
Option Description itInteract with the container and be a pseudo-terminal psmysql2Running container name mysqlConnects to a database instance -uSpecifies the user account used to connect -pUse this password when connecting -
Connect to the database instance example
$ docker exec -it psmysql2 mysql -uroot -pYou are prompted to enter the password, which is
secret.Enter password:You should see the following result.
Expected output
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.4.0-1 Percona Server (GPL), Release 1, Revision 238b3c02 Copyright (c) 2009-2024 Percona LLC and/or its affiliates Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-
-
Check the list of databases to make sure, the backed up,
mydbdatabase is in the list.mysql> show databases;Expected output
+--------------------+ | Database | +--------------------+ | information_schema | | mydb | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.03 sec) -
Use the
mydbdatabase.mysql> use mydb;Expected output
Database changed -
Check that your table contains data
mysql> SELECT * FROM employees;Expected output
+----+--------------------+-----------------------------------+-------------+ | id | name | email | country | +----+--------------------+-----------------------------------+-------------+ | 1 | Erasmus Richardson | [email protected] | England | | 2 | Jenna French | [email protected] | Canada | | 3 | Alfred Dejesus | [email protected] | Austria | | 4 | Hamilton Puckett | [email protected] | Canada | | 5 | Michal Brzezinski | [email protected] | Poland | | 6 | Zofia Lis | [email protected] | Poland | | 7 | Aisha Yakubu | [email protected] | Nigeria | | 8 | Miguel Cardenas | [email protected] | Peru | | 9 | Luke Jansen | [email protected] | Netherlands | | 10 | Roger Pettersen | [email protected] | Norway | +----+--------------------+-----------------------------------+-------------+ 10 rows in set (0.00 sec)