删除mongdb容器后如何恢复mongodb数据

时间:2017-05-15 07:10:55

标签: mongodb docker

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

但今天我删除了mongodb粗心。

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

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

我现在只拥有的数据库文件: enter image description here

我使用的容器是tutum / mongodb.my 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

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

我把mongod.lock以外的文件放在我的新容器中,但我的mongodb无法运行。 它是截图: enter image description here

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:

the logs under tutum/mongodb:3.0

2 个答案:

答案 0 :(得分:0)

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

1 - 你拍了一个文件系统快照 =&GT;您可以在数据文件夹中解压缩快照(查看mongod.conf中数据文件夹的位置)。

2 - 您使用了mongodump命令 =&GT;你需要使用mongorestore命令

答案 1 :(得分:0)

我在 mongodb 中挣扎,并且我自己在重新启动时缺乏持久性存储。在这里阅读您的帖子让我想知道这意味着什么:

来自您的 mongod.conf:

禁用预写日记

nojournal = 真

以及来自您的环境变量:

日志=是

也许你的环境应该是:

NOJOURNAL=false

NOJOURNAL=no

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

我个人终于能够使用这个 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