Posted under » MySQL » System Admin on 17 May 2025
We continue from Percona MySQL and XtraBackup The following steps describe how to restore your backup to another Percona Server Docker container and check whether the data is available.
Previously, We have created myvol for perconek. We want to create another Percona Server perkonek and need another volume.
$ docker volume create myvol2
The reason for creating the the volume first is because we want to be able to clear the contents of myvol2 later. Now lets create the 2nd server, perkonek.
$ docker run -d -p 6063:3306 --name perkonek \ -e MYSQL_ROOT_PASSWORD=secret \ -v myvol2:/var/lib/mysql \ percona/percona-server:8.0
Stop perkonek container.
Remove all created files in myvol2 to allow xtrabackup restore data to myvol2
$ docker stop perkonek $ docker run --volumes-from perkonek -v backupvol:/backup_8034 -it \ --rm --user root percona/percona-xtrabackup:8.0.34 /bin/bash -c "rm -rf /var/lib/mysql/*"
The --rm option automatically removes the temporary container created from percona/percona-xtrabackup:8.0.34 image after the container exits. If the command executes successfully, the expected output is empty.
Restore backup of perconek from backupvol to a new perkonek instance.
$ docker run --volumes-from perkonek -v backupvol:/backup_8034 -it --rm --user root \ percona/percona-xtrabackup:8.0.34 /bin/bash -c \ "xtrabackup --copy-back --datadir=/var/lib/mysql/ --target-dir=/backup_8034"
This command restores the backup files from the backup_8034 volume to the perkonek container. It uses the percona/percona-xtrabackup:8.0.34 image to run a temporary container with root privileges. It executes the xtrabackup tool with the --copy-back option, which copies the files from the backup_8034 volume to the /var/lib/mysql/ directory in the perkonek container. The command uses –rm option to delete the temporary container after it exits.
To avoid permission issues when running perkonek container, you need to change the owner because the files were restored by root user and perkonek will use mysql user.
$ docker run --volumes-from perkonek -v backupvol:/backup_8034 -it --rm --user root \ percona/percona-xtrabackup:8.0.34 /bin/bash -c "chown -R mysql:mysql /var/lib/mysql/"
*tip : When you inspect the volume (myvol2), the owner is a number like 1001 which is docker user mysql. The group is root. This is useful if you want to rsync from one docker to another.
Start the perkonek container
$ docker start perkonek
Connect to the database instance to check if backup was restored.
You need to clean up after backup because it will just use the existing files. It also save disk space. To remove a docker container, use the command docker rm followed by the container name or the container ID. To remove a docker image, use the command docker rm followed by the image ID or name and the tag. The example uses the -f option to force the removal.
Remove perconek, perkonek and pxb Docker containers and volume
$ docker container rm perkonek -f $ docker container rm pxb -f $ docker volume rm backupvol $ docker volume rm myvol2
If you want to see all your volumes.
$ docker volume ls $ docker volume inspect 03573347
While you are housekeeping, you might want to delete others by using Portainer