MongoDB Failed: can't create ActualPath object from path dump: stat dump: no such file or directory - mongodb

I have a bunch of mongo databases that I need to restore. I used mongodump to get the backup directories, which include the collections inside of them. Something like this:
|- mydir
|-- db1
|--- collection1
|--- collections2
|-- db2
|--- collection1
|--- collections2
I cd into mydir and do mongorestore and I get the following error:
2016-07-25T10:41:12.378-0400 using default 'dump' directory
2016-07-25T10:41:12.378-0400 Failed: can't create ActualPath object from path dump: stat dump: no such file or directory
Then I try to restore a specific database like this: mongorestore db2 and get the following errors:
2016-07-25T10:47:04.413-0400 building a list of dbs and collections to restore from db2 dir
2016-07-25T10:47:04.413-0400 don't know what to do with file "db2/collection1.bson", skipping...
2016-07-25T10:47:04.413-0400 don't know what to do with file "db2/collection1.metadata.json", skipping..."db2/collection2.bson", skipping...
2016-07-25T10:47:04.413-0400 don't know what to do with file "db2/collection2.metadata.json", skipping...
2016-07-25T10:47:04.414-0400 done
No matter what I do or what I try, I alternate between these two errors. And it's the same for any of the databases I use.
I tried using the --db flag, the -d parameter, setting the dump path as the third argument (mongorestore --db [db] [dump_path]). Everything I found around Stackoverflow. Nothing.
I'm stuck on this and I have no idea how to proceed.
EDIT
OS: Ubuntu 14.04
Installed MongoDB following this guide:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

mongorestore with no dump_path positional argument is expecting there to be a folder named dump in your current working directory. If the folder dump does not exist, you will get the "can't create ActualPath..." error.
So basically if you do not have a folder named dump, you will need to pass that positional argument. So from the parent directory of mydir run:
mongorestore mydir
If you want to use the --db option you will need to specify the dump path all the way down to the directory that contains the .bson files for that database or a specific .bson file.
So for example to restore all collections for db1:
mongorestore --db db1 ./db1
Or to just restore collection1:
mongorestore --db db1 ./db1/collection1.bson

Related

Why mongorestore always returning the error that directory not found even with correct file path?

I want to import some data in mongoDb database's collection. That collection already have some data and i want to import some more data into it. So for that i am using this command
mongorestore --drop -d local-db -c users /Documents/cwc/mongo-backups/Users.bson
but this command is always returning this error
Failed: mongorestore target '/Documents/cwc/mongo-backups/Users.bson' invalid: stat /Documents/cwc/mongo-backups/Users.bson: no such file or directory
How can i fix this?

MongoDb: How to import dump data from .gz file?

I want to import dump data from my .gz file.
Location of file is home/Alex/Documents/Abc/dump.gz and the name of db is "Alex".
I have tried mongorestore --gzip --db "Alex" /home/Alex/Documents/Abc/dump.gz
But it shows error:
2018-10-31T12:54:58.359+0530 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
2018-10-31T12:54:58.359+0530 Failed: file
/home/Alex/Documents/Abc/dump.gz does not have .bson extension.
How can I import it?
Dump command:
mongodump --host localhost:27017 --gzip --db Alex --out ./testSO
Restore Command:
mongorestore --host localhost:27017 --gzip --db Alex ./testSO/Alex
Works perfectly!
While using archive:
Dump command:
mongodump --host localhost:27017 --archive=dump.gz --gzip --db Alex
Restore Command:
mongorestore --host localhost:27017 --gzip --archive=dump.gz --db Alex
Note:- While using archive you need to stick with the database name.
Different database name or collection name is not supported. For more info.
This is what worked for me in the latest versions (100.5.1) of mongodump.
mongorestore --uri=<CONNECTION_URI> --gzip --archive=<ARCHIVE_NAME> --nsFrom "<SOURCE_DB_NAME>.*" --nsTo "<DEST_DB_NAME>.*"
Unpack .tgz files and restore the DB
tar zxvf fileNameHere.tgz
mongorestore --port 27017 -u="username" -p="password" --authenticationDatabase admin /bacup_path
mongorestore doesn't find the BSON files inside the gzip file because the mongodump was made with different paths than the restore one.
To solve the problem, the fastest and safest way is to extract the gzip file and go to the upper folder containing the json and bson files for run the mongorestore.
For example, the dump.gz file was made in such a way that the backup are saved within the data/backup/mongo/dump/ path folders
Extracting the dump.gz file with command tar -xvf dump.gz you will find a folder named data with the subfolders data/backup/mongo/dump/ inside (inside the dump folder are present all backup file with json and bson extension, these files represent databases and collections, etc.)
Go to the higher folder, that containing the dump folder eg. cd data/backup/mongo/
Now you can run the restore command
mongorestore --authenticationDatabase admin dump/
Where dump/ is the folder that containing the backup files.
You may need to use the arguments -h to point the server host (eg. localhost) and -u followed by the username enabled to make the restore operations (eg. root)

mongodump with different folder name

Is there a way to dump mongo database to a specific folder name?
Lets say I have a db named myDb
When I use:
mongodump --db myDb
It generates a dump folder with a myDb folder inside it
Is it possible to get something like dump/mySpecifiedFolder from mongodump?
You cannot change the name of the myDB folder, since that's named for the database which it contains, but you can change the location of the myDb folder. To do this, use the --out / -o parameter.
From the docs:
--out , -o
Specifies the directory where mongodump will write BSON files for the dumped databases. By default, mongodump saves output files in a directory named dump in the current working directory.
So, this command ...
mongodump --db myDb -o /some/path/
... would cause mongodump to create /some/path/myDb.
In my discovery of doing a mongodump, please note that the default location can be the Desktop when outputting.
Example
"C:\Program Files\MongoDB\Server\3.4\bin\mongodump.exe" --host localhost --port 27017 --db local --out dump/dpusers
On your Desktop, the dump folder will be created with the subfolder "dpusers" and inside that folder is another folder named the same as your database name.

Mongodb monogorestore "root directory must be a dump of a single database"

I'm trying to restore a mongodump to a differently named database (which should be possible via --db <dbname> switch).
My working directory contains a single dump folder, which contains a single db dump.
However, when I try this command:
mongorestore --port xxxxx --db some_destination_db
I get the following error:
ERROR: ERROR: root directory must be a dump of a single database
ERROR: when specifying a db name with --db
I have no idea why I'm getting this, and can't find any help on google. Anyone have any ideas?
You need to include the path of the source db dump directory to restore from (as at MongoDB 2.6).
For example, if restoring from "twitter" to "some_destination_db" your command line would be similar to:
mongorestore --port xxxxx --db some_destination_db dump/twitter
May be your destination path contains some subfolders

How to use the dumped data by mongodump?

I have used mongodump to dump my database of mongodb, it created some bson files under dump/mydb
But I don't know how to use them. I tried mongoimport, but seems it can't import bson data. Then how to use these bson files? How to import them to another mongodb?
You need to use mongorestore, not mongoimport ... which is used for things like importing json, or csv, etc.
From the back-up-with-mongodump docs:
mongodump reads data from a MongoDB database and creates high fidelity BSON files which the mongorestore tool can use to populate a MongoDB database.
mongodump and mongorestore are simple and efficient tools for backing
up and restoring small MongoDB deployments, but are not ideal for
capturing backups of larger systems.
You can read more about mongorestore in the docs below; I'd take a look and read up on them as they are very helpful.
http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-mongorestore
You can also check out http://learnmongo.com for tips and help!
I am using mongodump, mongorestore for daily backups and restoring from backup. I have two .bat files:
First, for backup, where you need just specify host database name and backup folder:
SET host=localhost:27020
SET dbNameToDump=MyDB
SET backupsFolder=Backups
mongodump.exe --host %host% --db %dbNameToDump%
SET date="%date:~10,4%-%date:~4,2%-%date:~7,2%.%time:~0,2%-%time:~3,2%"
cd %backupsFolder%
md %date%
xcopy /e ..\dump %date%
rmdir /s /q ..\dump
Above bat file create folder with name like this 2011-03-31.11-17(yyyy-MM-dd.hh-ss) in folder Backups with dumped collections from specified database. In files explorer it looks like so:
Second bat file i use for retore specified dumped files(here you also need specify database name and folder with dumped files):
SET host=localhost:27020
SET dbNameToRestore=MyDB
SET restoreFolder=Restore
mongorestore.exe --host %host% --db %dbNameToRestore% %restoreFolder%
In files explorer:
In additional, i am using windows schedule to automate backup process.
Hope above information will be useful for someone.
As mentioned in the previous answers, you have to use mongorestore instead of mongoimport. Adding to the previous answers, when your mongodb is running, execute the following command to restore your dump from the dump directory,
mongorestore dump
This will import all the collections into your mydb database. However this doesn't drop the database before restoring. If you wish to drop the database before importing,
mongorestore --drop dump
The bson files in the mydb directory will be restored as the collections inside mydb database. For more info on mongorestore check the documentation here.
Use mongorestore. mongoimport works on the output of mongoexport. mongodump & mongorestore work on binary data files while import / export work on json, csv, etc.. (human readable formats)
For resolving this, I copied the dump folder,dbdump(which contains bson files) to bin directory of mongodb and executed the below commands in command prompt:
1.
cd "path to MongoDB's bin folder"
(Example: cd C:\Program Files\MongoDB\Server\3.2\bin)
2.
mongorestore.exe --dir ./directory name --db database-name
(Example: mongorestore --dir ./dbdump --db testdb)
All bson files in the dump folder will be imported into your database.
You can verfiy this by executing the below commands :
cd "path to MongoDB's bin folder"
mongo.exe
show dbs;
For mongo version 3 and above use the command below:
mongorestore --host=localhost --port=27017 --username=root --authenticationDatabase=admin --db=test dump_folder/
Mongo will ask password after that