How to Backup, Restore or Migrate data volumes in a docker container?

0 votes
What is the procedure for backup,restore data volumes in docker? Could you please explain?
Jul 3, 2019 in Docker by Daisy
6,125 views

1 answer to this question.

0 votes

Steps to Backup a container

1)      Launch a new container and mount the volume from the dbstore container

2)      Mount a local host directory as /backup

3)      Pass a command that tars the contents of the dbdata volume to a backup.tar file inside our /backup directory.

$ docker run --rm --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata

Restore container from backup

With the backup just created, you can restore it to the same container, or another that you made elsewhere.

For example, create a new container named dbstore2:

$ docker run -v /dbdata --name dbstore2 ubuntu /bin/bash 

Then un-tar the backup file in the new container`s data volume:

$ docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"

answered Jul 3, 2019 by Sirajul
• 55,420 points

So there aren't any issues with live containers? I saw that databases should be backup with replication but isn't there the same issues with other containers? Shouldn't they be stopped before backup? If so how should it be done? I really lost there, i've looked it up for 2 days and i don't have any clue on how to do it properly...

About container backup: https://blog.linuxserver.io/2019/10/01/updating-and-backing-up-docker-containers-with-version-control/ but not much on data backup: "App data can be backed up via tar and stored in an archive file on the same machine or a remote machine.".

Any clue would be highly appreciated :)

I am not clear with your doubt. But if you are looking for backup of your data, then create one persistent volume and mount it. Now you can transfer this volume in any other container.

Related Questions In Docker

0 votes
1 answer

How to create a container and run images in docker?

Look for what all images you have ...READ MORE

answered Feb 22, 2019 in Docker by Kalgi
• 51,890 points
274 views
0 votes
1 answer

How to install packages in a Docker container?

Hi@akhtar, To install packages in a docker container, ...READ MORE

answered Apr 15 in Docker by MD
• 41,500 points
2,372 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,200 points

edited Oct 16, 2018 by lina 14,066 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,940 points
1,134 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 57,550 points
659 views
0 votes
2 answers

How to execute docker exec commande inside a docker container ?

You need to get inside the container ...READ MORE

answered Aug 13, 2019 in Docker by Sirajul
• 55,420 points
899 views
0 votes
2 answers

How do I copy a file from docker container to host?

Instead of using docker run you could ...READ MORE

answered Aug 13, 2019 in Docker by Sirajul
• 55,420 points
17,238 views