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:
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:
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.
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:
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?