将mongo-data链接到/data/db文件夹到卷Mongodb Docker [英] Link mongo-data to /data/db folder to a volume Mongodb Docker

查看:66
本文介绍了将mongo-data链接到/data/db文件夹到卷Mongodb Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心删除了一部分docker mongo-data:/data/db,我有该文件夹的副本,现在的问题是当我运行docker-compose up mongodb容器时无法启动,并给出了mongo_1错误错误代码和mongo-data文件夹的更多详细信息在下面的代码14退出,您能帮助我吗

I accidentally deleted a volume of docker mongo-data:/data/db , i have a copy of that folder , now the problem is when i run docker-compose up mongodb container doesn't start and gives an error of mongo_1 exited with code 14 below more details of the error and the mongo-data folder , can you someone help me please

在docker-compose.yml

in docker-compose.yml

卷:-./mongo-data:/data/db

volumes: - ./mongo-data:/data/db

推荐答案

从备份文件还原

从docker容器中的失败的mongodb中修复损坏的文件的分步过程:

Restore from backup files

A step-by-step process to repair the corrupted files from a failed mongodb in a docker container:

  1. !开始之前,请复制文件.!

  1. ! Before you start, make copy of the files. !

确保您知道容器中正在运行哪个版本的图像

Make sure you know which version of the image was running in the container

使用新的容器来生成要运行的修复程序,如下所示:

Spawn new container with to run the repair process as follows

docker run -it -v <data folder>:/data/db <image-name>:<image-version> mongod --repair

  • 一旦修复了文件,就可以从 docker-compose

    如果修复失败,通常意味着文件已损坏,无法修复.仍然有机会通过将数据导出为此处所述进行修复.

    If the repair fails, it usually means that the files are corrupted beyond repair. There is still a chance to repair it with exporting the data as described here.

    数据库一直在处理文件,因此文件在磁盘上不断更改.另外,在将内部存储器缓冲区中的某些更改刷新到文件系统之前,数据库会将它们保留在其中.尽管数据库引擎在通过两阶段提交过程(首先更新事务日志而不是数据文件)来确保数据库可以从突然故障中恢复方面做得很好,但是在复制文件时可能会出现以下损坏:将阻止数据库恢复.

    The database is constantly working with the files, so the files are constantly changed on the disks. In addition, the database will keep some of the changes in the internal memory buffers before they are flushed to the filesystem. Although the database engines are doing very good job to assure the the database can recover from abrupt failure by using the 2-stage commit process (first update the transaction-log than the datafile), when the files are copied there could be a corruption that will prevent the database from recovery.

    造成这种损坏的原因是,复制过程不知道数据库写入过程的进度,这会产生竞赛条件.用很简单的话来说,当数据库处于编写过程中时,复制过程将创建文件的副本,该副本将被更新一半,因此将被破坏.

    Reason for such corruption is that the copy process is not aware of the database written process progress, and this creates a racing condition. With very simple words, while the database is in middle of writing, the copy process will create a copy of the file(s) that is half-updated, hence it will be corrupted.

    当数据库编写器正在写入文件时,我们称它们为 hot 文件.从操作系统的角度来看, hot files 是术语,而MongoDB也使用 hot backup 这个术语,从 MongoDB 角度来看.热备份表示备份是在数据库运行时进行的.

    When the database writer is in middle of writing to the files, we call them hot files. hot files are term from the OS perspective, and MongoDB also uses a term hot backup which is a term from MongoDB perspective. Hot backup means that the backup was taken when the database was running.

    要进行适当的快照(确保文件为 cold ),您需要按照

    To take a proper snapshot (assuring the files are cold) you need to follow the procedure explained here. In short, the command db.fsyncLock() that is issued during this process will inform the database engine to flush all buffers and stop writing to the files. This will make the files cold, however the database remains hot, hence the difference between the terms hot files and hot backup. Once the copy is done, the database is informed to start writing to the filesystem by issuing db.fsyncUnlock()

    请注意,该过程更为复杂,并且可以随着数据库的不同版本而改变.在这里,我对其进行了简化,以说明有关文件快照问题的观点.为了确保正确且一致的备份,请始终按照所使用数据库版本的说明步骤进行操作.

    Note the process is more complex and can change with different version of the databse. Here I give a simplification of it, in order to illustrate the point about the problems with the file snapshot. To secure proper and consistent backup, always follow the documented procedure for the database version that you use.

    建议的备份方法

    首选备份应始终是数据转储方法,因为这样可以确保即使在升级/降级的数据库引擎的情况下也可以还原. MongoDB 提供了一个非常有用的工具,称为 mongodump ,可用于通过转储数据而不是文件副本来创建数据库备份.

    Suggested backup method

    Preferred backup should always be the data dump method, since this assures that you can restore even in case of upgraded/downgraded database engines. MongoDB provides very useful tool called mongodump that can be used to create database backups by dumping the data, instead by copy of the files.

    有关如何使用备份工具以及其他备份方法的更多详细信息,请阅读一章.

    For more details on how to use the backup tools, as well as for the other methods of backup read the MongoDB Backup Methods chapter of the MondoDB documentation.

    这篇关于将mongo-data链接到/data/db文件夹到卷Mongodb Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆