我有工作命令备份和恢复我的mongodb docker容器的docker卷,我的docker容器的名称是 tsl.api.example.db.container
好的,我们走了:我验证我在名为 example
的MongoDb集合中有3条记录 .
我添加一个 test.txt
文件 tsl.api.example.db.container
的volume / data / db来帮助证明我正在存档并正确恢复:
docker exec -it tsl.api.example.db.container bash
cd /data/db
touch text.txt
我的备份命令是
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 .
路径 /data/db
is correct MongoDb路径,是我容器的容量 .
我验证backup.tar存在于localhost上的/ backup / volumes中:
我现在关闭了tsl.api.example.db容器:
docker rm -fv tsl.api.example.db container
然后删除它的悬空音量:
docker volume prune
前两个步骤的屏幕截图:
然后我启动一个名为 tsl.api.example.db.container.2
的新容器,它使用 tsl.api.example.db.container
使用的相同图像,运行正常,我查询mongodb并且 example
集合没有记录 .
我使用命令将卷backup.tar恢复到新容器
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”
backup.tar存档已成功解压缩并复制到 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卷 .
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
所以我尝试停止并启动我的新MongoDB容器,看看是否会刷新我的集合:
docker stop tsl.api.example.db.container.2
docker start tsl.api.example.db.container.2
当然,容器不会重新启动,这是最后的日志条目:
有关在尝试恢复MongoDB Docker容器卷时可能排除哪些文件的任何建议?当我backup.tar时,我应该排除aka not archive mongod.lock吗?还有其他建议吗?