How do i restore old MongoDB files? (extensions end with numbers) - mongodb

How can I restore an old MongoDB backup that I believe was made by copying the raw db files? (They did not use a dump command)
It was delivered compressed in a .7z format, which decompressed to the following files:
mydb_2014.1
mydb_2014.2
mydb_2014.3
mydb_2014.4
mydb_2014.5
mydb_2014.ns
I've tried mongorestore but it generates errors saying "don't know what to do with file ..., skipping"

It should be possible to just start up a mongod instance while specifying the path to the files in question:
mongodb --dbpath /path/to/files
You should try to use a version of MongoDB that matches to the version that was in use when the backup was taken. It looks like these files are from the MMAPv1 storage engine, so you may also need to specify --storageEngine mmapv1 if you're using MongoDB 3.2 or later.

Related

Restoring MongoDB using only .wt files

My PC crashed. Can I use the .wt files to get my data back?
.wt files from the old MongoDB
You can restore your .wt WiredTiger files downloaded from your Atlas Backup (which unzips or untar as a restore folder) to your local MongoDB.
First, make a backup of your /data/db path. Call it /data_20200407/db. Second, copy paste all the .wt files from your Atlas Backup restore folder into your local /data/db path. Restart your Ubuntu or MongoDB server. Start your Mongo shell and you should have those restored files there.
Keep your wt files at location C:\data\db also check permissions
Go to bin folder of mongodb and hit following command
mongod --dbpath "C:\data\db"
Go to same bin folder and hit mongo command there
I suggest to use noSQLBooster to view db and collections.
make sure you have C:\Programfiles\mongodb\server\4.4\bin\ path set in Environment variables
I restored my db with some BSON files and then I repaired it so it can sync up my db and get my most recent files. I used Robo3T to repair my DB and it worked

mongodb is not start after restoring /var/lib/mongodb manually

Our server's raid failed today. Right now we have a zip file of mongodbPath but after we extract it, we can not start mongo db again.
I will appreciate any help.
After a lot of searches and contacting with MongoDB's support we fond out that we rsync MongoDB directory when it was writing.
So we cannot restore data and we had data lost!
If you want to use rsync for getting backup of MongoDB you should stop it.
This may help.

Downgrade mongodb from v3.2.10 to v2.4.9, keeping the same data files

I have the /data/db files from a MongoDB v3.2.10 installation using WiredTiger. How can I run MongoDB v2.4.9, on ubuntu, in a way that it can use the same data files in /data/db?
FYI, I have copied /data/db to the new mongodb directory, but it hasn't worked.
To import a datapath, you can pass the dbpath flag to the mongodb daemon when initializing it. Example:
mongod --dbpath /data/db
If you want to restore a previous mongodb dumpfile, you can use the mongorestore option. Example:
mongorestore --db yourDB /data/db
This will restore your /data/db to a new database called yourDB
Hope my answer was helpful.
No: the files are incompatible because they are from a different storage engine.
Your v.3.2 installation was running with the WiredTiger storage engine; that is why your data files have the .wt extension. This storage engine was only introduced in MongoDB v3.0; before that, the only storage engine available was MMAPv1.
So your MongoDB v2.4.9 can only run with MMAPv1 data files; when you give it WiredTiger data files, it does not know what to do with them and fails.
If you have to downgrade, then you will need to use mongodump as part of a conversion of the data from one storage engine to another:
run MongoDB v3.2.10 with the WiredTiger data files
run mongodump to produce a BSON dump of the entire database.
install MongoDB v3.2.10
install MongoDB v2.4.9
run mongorestore to import the data from the BSON files into the MMAPv1 data storage engine.

Where are the db files? at /var/lib/mongodb I cant find any increase in size. I ran very big loop to create lakhs of objects

I am using UBUNTU, from /etc/mongod.conf, I found that /var/lib/mongdb is the path for data.
I have found some files like collectionname.0, .1, .ns in that directory. but when I run a very big loop(lakhs), I am able to get them back using mongo shell, but that mongodb directory size is not increasing, so there must be someother place where this data is being stored
What is that place?
There is no another place. As indicated by #itsbruce, in Ubuntu it's /var/lib/mongodb.
On a non-packaged installation (on Linux), i.e. without a /etc/mongodb.conf file, the default is /data/db/ (unless otherwise specified).
You can modify the switch "--dbpath" on the command line to designate a different directory for the mongod instance to store its data. Typical locations include: /srv/mongodb, /var/lib/mongodb or /opt/mongodb.
(Windows systems use the \data\db directory.) If you installed using a package management system.
I recommend using the db.collection.stats command as outlined here to monitor the size of your collection as you insert data. The link also explains what each field (in the output) means.
That is the correct data location for MongoDB on Ubuntu. MongoDB pre-allocates filespace. Are you sure you have generated more data than would fit into the initial pre-allocated files? Try blowing away any existing data files and restarting Mongo with the --noprealloc flag. Then add data.

MongoDB db files movement

I am using mongodb and I have changed the dbpath. Can I just copy all the files from the earlier dbpath to the new dbpath?
PS: I have come across the mongodump alternative which might be a bit tedious. So I am interested in knwoing whether plain copying work?
Yes, you can just do a normal copy if you shutdown your mongod first. You don't need to copy mongod.lock.