4

Hello I have a simple script that dumps a mongo db using a shell command from a remote mongo server, and then runs a shell command to restore that db to the dev db on another server.

the script lives in /home/ubuntu/mongo and the dump is in /home/ubuntu/mongo/dump

here is my code:

!/usr/bin/python

import time
import subprocess
import os
import shutil

now=int(time.time())
cmd="mongodump --host  -db chronotrack"
print subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

cmd="mongorestore --host   -db chronotrack  dump/"
print subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

#mongorestore --host  --port 3017 --db mongodevdb --username mongodevdb --password YourSecretPwd --drop /backup/dump

Here is my error:

ERROR: root directory must be a dump of a single database
       when specifying a db name with --db
usage: mongorestore [options] [directory or filename to restore from]
options:
  --help                  produce help message
  -v [ --verbose ]        be more verbose (include multiple times for more
                          verbosity e.g. -vvvvv)
  --version               print the program's version and exit
  -h [ --host ] arg       mongo host to connect to ( <set name>/s1,s2 for sets)
  --port arg              server port. Can also use --host hostname:port
  --ipv6                  enable IPv6 support (disabled by default)
  -u [ --username ] arg   username
  -p [ --password ] arg   password
  --dbpath arg            directly access mongod database files in the given
                          path, instead of connecting to a mongod  server -
                          needs to lock the data directory, so cannot be used
                          if a mongod is currently accessing the same path
  --directoryperdb        if dbpath specified, each db is in a separate
                          directory
  --journal               enable journaling
  -d [ --db ] arg         database to use
  -c [ --collection ] arg collection to use (some commands)
  --objcheck              validate object before inserting
  --filter arg            filter to apply before inserting
  --drop                  drop each collection before import
  --oplogReplay           replay oplog for point-in-time restore
  --keepIndexVersion      don't upgrade indexes to newest version
2
  • btw i removed the hostnames for obvious reasons. Commented Feb 13, 2015 at 17:04
  • No need to clarify about the hostnames. We all understand! :) Commented Feb 13, 2015 at 17:05

1 Answer 1

2

Found the answer :

"mongorestore --host  -db chronotrack  --drop dump/chronotrack"
Sign up to request clarification or add additional context in comments.

2 Comments

Please explain the answer, for the benefit of future users.
I assume that in original post op missed name of dump (which is "chronotrack") in "--drop dump/" part and tried to specify only dump destination instead of dump-file itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.