# How to use xtrabackup to back up mysql data in docker container？

**URL:** <https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162>\
**Category:** Percona XtraBackup\
**Created:** [August 19, 2019, 4:53am UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162 "2019-08-19T04:53:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peng19832](https://avatars.discourse-cdn.com/v4/letter/p/7993a0/32.png) [@peng19832](https://forums.percona.com/u/peng19832)\
**Post date:** [August 19, 2019, 4:53am UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162/1 "2019-08-19T04:53:32Z")

</div>

Such as the title：  
How to use xtrabackup to back up mysql data in docker container？

---

<div class="post-metadata">

**Author:** ![lorraine.pocklington](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/lorraine.pocklington/32/37_2.png) [@lorraine.pocklington](https://forums.percona.com/u/lorraine.pocklington)\
**Post date:** [August 19, 2019, 5:04am UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162/2 "2019-08-19T05:04:38Z")

</div>

Do you mean from within a Docker container, or to use the docker container as a destination?  
In the first instance, this blog might help you. Although it’s about windows, it addresses using Percona XtraBackup in Docker [URL][https://www.percona.com/blog/2017/03/20/running-percona-xtrabackup-windows-docker/[/URL]](https://www.percona.com/blog/2017/03/20/running-percona-xtrabackup-windows-docker/%5B/URL%5D)

If that’s not enough to get you going, feel free to come back with additional details of what you are trying to achieve.

---

<div class="post-metadata">

**Author:** ![peng19832](https://avatars.discourse-cdn.com/v4/letter/p/7993a0/32.png) [@peng19832](https://forums.percona.com/u/peng19832)\
**Post date:** [August 20, 2019, 5:51am UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162/3 "2019-08-20T05:51:03Z")

</div>

We have some mysqld services that are running in the docker container.  
How to use xtrabackup to back up the database in the container.

---

<div class="post-metadata">

**Author:** ![vinicius.grippa](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vinicius.grippa/32/1246_2.png) [@vinicius.grippa](https://forums.percona.com/u/vinicius.grippa)\
**Post date:** [August 20, 2019, 10:49am UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162/4 "2019-08-20T10:49:30Z")

</div>

Hi,

In order to do the backup, we need to find the local directory on the host where the data exists as well as the internal IP that the container is using so the xtrabackup container can reach it. We can do this by using Docker inspect. As you’ll see below, the local source directory is /var/lib/docker/volumes/3704326a0cf27d1ea158be4c0224f53579d2a674642a90349713c1144da85a72/\_data and the IP address is 172.17.0.5.

```auto
$ sudo docker inspect vinnie_253823
...
"Mounts": [
{
"Type": "volume",
"Name": "3704326a0cf27d1ea158be4c0224f53579d2a674642a90349713c1144da85a72",
"Source": "/var/lib/docker/volumes/3704326a0cf27d1ea158be4c0224f53579d2a674642a90349713c1144da85a72/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
...
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "403064a581385aa12a91b0d2f4c318d496b53be9d00752682192dbea93632c41",
"EndpointID": "cf5257be0f558287fe043b19b533699428db465103b73b9235867fb4cb6e82cf",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.5",

```

Then replace it accordingly on the line below:

```auto
sudo docker run --rm -it -v[B] /var/lib/docker/volumes/3704326a0cf27d1ea158be4c0224f53579d2a674642a90349713c1144da85a72/_data[/B]:/var/lib/mysql -v [B]/home/vinicius.grippa/backup[/B]:/xtrabackup_backupfiles perconalab/percona-xtrabackup --backup --host=172.17.0.5 --user=root --password=percona --port 3306

```

​​​​​​

And the backup will be executed. The xtrabackup container will auto-destroy after completing the task. Don’t forget to change the user and password too.

---

<div class="post-metadata">

**Author:** ![peng19832](https://avatars.discourse-cdn.com/v4/letter/p/7993a0/32.png) [@peng19832](https://forums.percona.com/u/peng19832)\
**Post date:** [August 20, 2019, 8:22pm UTC](https://forums.percona.com/t/how-to-use-xtrabackup-to-back-up-mysql-data-in-docker-container/7162/5 "2019-08-20T20:22:39Z")

</div>

Ok,thanks.  
I will try
