【问题标题】:how to restore mongodb data after my mongdb container has been removed删除我的 mongodb 容器后如何恢复 mongodb 数据
【发布时间】:2021-03-06 19:24:13
【问题描述】:

我在 docker 容器中运行 mongodb,并且我有数据文件备份。

但今天我不小心删除了我的mongodb

我尝试运行另一个容器并将数据文件放入容器中,但它不起作用。

如何从数据文件中恢复我的数据?

我现在只有的数据库文件:

我使用的容器是tutum/mongodb。我的docker-compose.yml文件是

mongo_db: image: tutum/mongodb privileged: true restart: always ports: - 27016:27017 - 28016:28017 volumes: - /var/mongodb:/data/db environment: - MONGODB_PASS=xxxxxx - AUTH=yes

现在我想将我的数据从目录 /var/mongodb 恢复到我的新容器

我将 mongod.lock 以外的文件放入新容器中,但我的 mongodb 无法运行。 这是屏幕截图:

mongod.conf 是:

# Where to store the data.

# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongod.log

logappend=true

#port = 27017

# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1

# Disables write-ahead journaling
# nojournal = true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true

# Verbose logging output.
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#diaglog = 0

# Ignore query hints
#nohints = true

# Enable the HTTP interface (Defaults to port 28017).
#httpinterface = true

# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Replication Options

# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile

容器开始运行时容器在 env 中设置了 STORAGE_ENGINE 容器的环境是:

# mongod.conf
STORAGE_ENGINE=wiredTiger
HOSTNAME=bb544551ec2b
MONGODB_PASS=xxxxxx
LS_COLORS=
AUTH=yes
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/etc
SHLVL=1
HOME=/root
LESSOPEN=| /usr/bin/lesspipe %s
JOURNALING=yes
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env
OLDPWD=/

tutum/mongodb:3.0下的日志:

【问题讨论】:

  • 你好王凯文;图片在帖子中很有用,但确保帖子在没有它们的情况下仍然清晰。您可以直接将相关信息复制并粘贴到帖子中,而不是显示终端的屏幕截图吗? cfmeta.stackoverflow.com/questions/303812/…

标签: mongodb docker


【解决方案1】:

这取决于您执行备份的方式。

1 - 您拍摄了文件系统快照。
=> 你可以在你的数据文件夹中解压你的快照(检查你的数据文件夹所在的 mongod.conf)。

2 - 你使用了 mongodump 命令。
=> 你需要使用 mongorestore 命令

【讨论】:

  • 我没有做任何备份。我只有数据库文件(一些 .wt 文件)。我上传了一个关于我有什么文件的屏幕截图
  • 好的,所以您只需删除 mongod.lock 并将这些数据复制到您的数据文件夹中(在您的新容器中)
  • 我需要复制哪个文件?除了 mongod.lock 之外的所有文件还是仅 .wt 文件?
  • 除mongod.lock之外的所有文件
  • 我试过了,但失败了。我会在我的问题框中上传日志截图
【解决方案2】:

我正在为 mongodb 和我自己在重启时缺乏持久性存储而苦苦挣扎。在这里阅读您的帖子让我想知道这意味着什么:

来自您的 mongod.conf:

禁用预写日志

nojournal = true

并且来自您的环境变量:

日记=是

也许你的环境应该是:

NOJOURNAL=false

NOJOURNAL=否

(我也在为降价而苦苦挣扎)

我个人终于能够使用此 compose 部分保存数据 - 并通过设置 ENV 变量 NODE_ENV: production(在取决于 mongodb 服务的不同服务中)

    image: mongo:4.4
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: something
      MONGO_INITDB_ROOT_PASSWORD: otherthanthis
    volumes:
      - ./mongodata:/data/db:cached

【讨论】:

    猜你喜欢
    • 2021-02-26
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 2017-04-17
    • 2012-03-05
    • 2013-03-23
    相关资源
    最近更新 更多