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
14,121 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
• 59,230 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 23, 2019 in Docker by Kalgi
• 52,350 points
2,200 views
+1 vote
1 answer

How to install packages in a Docker container?

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

answered Apr 15, 2020 in Docker by MD
• 95,460 points
146,773 views
+1 vote
1 answer

How to mount a host directory in a Docker container?

Hi@akhtar, You can use the -v option in ...READ MORE

answered Dec 23, 2020 in Docker by MD
• 95,460 points
2,377 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,220 points

edited Oct 16, 2018 by lina 34,086 views
+2 votes
1 answer
+2 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
• 58,060 points
2,693 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
• 59,230 points
3,770 views
+1 vote
2 answers

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

Here is a way which you can ...READ MORE

answered Aug 28, 2018 in Docker by Damon Salvatore
• 5,980 points
28,554 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP