2

I am working on backup recovery for MongoDB 3.4. We have an instance that is running and being used. I set up a instance for doing testing of the backup and recovery process. In order to get data I did mongodump for each database and copied the files to my test server. Each backup write files to a directory that has the same name as the database. I used the gzip option to make it easier to move the files around. I am having issues trying to do the mongorestore. Can someone give me the syntax for mongorestore?

Here is the dump command

mongodump --port 27017 --authenticationDatabase admin -u my_admin_user
          -p password -o /backup_dir --gzip -d test_db

(split to multiple lines for readability)

These are the directories with the contents of my_test_db

root@my_vm:~/mongodb_backup_full_data_dump > ls -l
total 20
drwxr-xr-x. 2 root root 4096 Aug 24 13:30 admin
drwxr-xr-x. 2 root root 4096 Aug 24 13:51 data1
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data2
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data3
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 my_test_db
root@my_vm:~/mongodb_backup_full_data_dump > ls -l ./my_test_db/*
-rw-r--r--. 1 root root    24263 Aug 24 14:20 ./my_test_db/journal_entries.bson.gz
-rw-r--r--. 1 root root      132 Aug 24 14:20 ./my_test_db/journal_entries.metadata.json.gz
-rw-r--r--. 1 root root      481 Aug 24 14:20 ./my_test_db/journal_users.bson.gz
-rw-r--r--. 1 root root      107 Aug 24 14:20 ./my_test_db/journal_users.metadata.json.gz
-rw-r--r--. 1 root root 14438174 Aug 24 14:20 ./my_test_db/test_collection.bson.gz
-rw-r--r--. 1 root root      104 Aug 24 14:20 ./my_test_db/test_collection.metadata.json.gz

and, this is what happens when I try to do the restore:

mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password -o /backup_dir \
--gzip -d test_db /root/mongodb_backup_full_data_dump/test_db/journal_entries.bson.gz



2017-08-25T15:24:05.487-0400    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2017-08-25T15:24:05.487-0400    checking for collection data in /root/mongodb_backup_full_data_dump/mediax
2017-08-25T15:24:05.487-0400    Failed: error scanning filesystem: file /root/mongodb_backup_full_data_dump/mediax is a directory, not a bson file
  • Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/… – SqlWorldWide Aug 25 '17 at 18:05
  • I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing. – Gandolf989 Aug 25 '17 at 18:44
  • mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files? – SqlWorldWide Aug 25 '17 at 18:55
  • I tried using the directory only, the error is above. – Gandolf989 Aug 25 '17 at 19:26
0

Answer is

mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/

So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).

SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"

|improve this answer|||||
0

Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.

mongod --dbpath /data/db --replSet <replName>

Connect a mongo shell to the mongod instance

mongo

Initiate the new replica set.

rs.initiate()

MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.

For detailed information Please Click Here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.