0

I have working commands to backup and restore a docker volume for my mongodb docker container, the name of my docker container is tsl.api.example.db.container

Ok here we go: I verify that I have 3 records in a MongoDb collection called example.

I add a test.txt file tsl.api.example.db.container's volume /data/db to help prove that I am archiving and correctly restoring:

docker exec -it tsl.api.example.db.container bash
cd /data/db
touch text.txt

My back up command is

docker run --rm --volumes-from tsl.api.example.db.container -v /backup/volumes:/backup tsl.devops.basic.image tar cvf /backup/backup.tar -C /data/db .

Path /data/db is correct MongoDb path and is my volume for my container.

I verify backup.tar exists in /backup/volumes on the localhost: enter image description here

I now shut down tsl.api.example.db container:

docker rm -fv tsl.api.example.db container

And then delete it's dangling volume:

docker volume prune

Screenshot of previous two steps: enter image description here

I then start a new container called tsl.api.example.db.container.2,that uses the same image that tsl.api.example.db.container used , it is running fine, I query mongodb and the example collection has no records.

I restore the volume backup.tar to the new container with command

docker run --rm --volumes-from tsl.api.example.db.container.2 -v /backup/volumes:/backup tsl.devops.basic.image bash -c "cd /data/db && tar -xvf /backup/backup.tar"

The backup.tar archive is successfully unpacked and copied to tsl.api.example.db.container.2's volume /data/db, I can see my text.txt to help prove that I archived and unpacked correctly into the new container's volume.

enter image description here

And yet, my example collection still has 0 records, I expected the 3 records that existed in my first container, when I archived /data/db

So I try stopping and starting my new MongoDB container to see if that will refresh my collections:

docker stop tsl.api.example.db.container.2
docker start tsl.api.example.db.container.2

And of course, the container will not start back up, and here is the last log entries:

enter image description here

Any suggestions on what files to possibly exclude when trying to restore a MongoDB Docker container volume? Should I exclude aka not archive the mongod.lock when I backup.tar? Any other suggestions?

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • I think the core of the problem is in how you packed the backup file. Check https://stackoverflow.com/questions/18681595/tar-a-directory-but-dont-store-full-absolute-paths-in-the-archive. – ichigolas Oct 19 '17 at 20:21
  • yes you are correct @nicooga – Brian Ogden Oct 19 '17 at 20:32
  • I fixed that problem, thanks for your assistance @nicooga. I also altered my question now, my working tar archive, when unpacked does not restore any data to a new mongodb container and new associated volume – Brian Ogden Oct 19 '17 at 21:11

0 Answers0