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.
Related
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.
MongoDB documentation has the following line. What do they mean when they say, mongorestore can directly write to MongoDB data files without an active mongod? Does it mean it can write even if a mongod instance is not ready and reachable, or, is there something called inactive mongod instance. I am finding it difficult to understand. Can someone explain me this?
mongorestore can write data to either mongod or mongos instances, in addition to writing directly to MongoDB data files without an active mongod.
Prior to v3.x mongorestore could be configured to write directly to data files rather than writing into data files via mongod.
The term "data files" here refers to the contents of a dbpath directory so, by specifying --dbpath you could tell mongorestore to attach to the data files in that directory and insert data into those files without having to go through a mongod instance.
I am going to be doing some major DB restructuring in MongoDB that converts a bunch of records. I've ran this script against a copied DB locally and it works fine, so it should also work on the production database.
Is there an easy way of copying a DB instance into a new DB? I figured I could shut down MongoDB and copy the files into a new directory, rename them to the new DB, and then move them into the MongoDB data directory.
It's usually pretty slow to copy large DB files like that, so I wondered if there was a Mongo-specific way of copying DB's.
In case it is sufficient to copy only some collections, you can copy them as follows without shutting down the db server:
http://xmlquerying.blogspot.de/2012/10/copying-data-between-mongo-databases.html
Otherwise use mongodump and mongorestore.
http://docs.mongodb.org/manual/tutorial/backup-databases-with-binary-database-dumps/
I have a mongodb v2.4.6 running on ubuntu 13.04. It is known that mongodb store all data in /var/lib/mongodb. Now the mongodb is running out of the hard disk. Fortunately, I got a new hard disk which is installed, fdisked, formated and got a name /dev/sda3. Unfortunately I don't know how to let the mongodb make use of the new hard disk because my knowledge on ubuntu and mongodb is very limited. After some research in internet, it seems that I should execute the following command
sudo mount /dev/sda3 /var/lib/mongodb
Is this what I need to do to let mongodb use the new disk? If so, will mongodb automatically and intelligently increase its data to this disk? Is there any othere things I should do? Thank you.
Unfortunately this one will not be that straightforward. Even if you succeed with the mounting it will not move the files at all. What you can do is to
mount the disk elsewhere (mkdir /var/lib/mongodb1, mount /dev/sda3 /var/lib/mongodb1)
stop mongo
copy the files from /var/lib/mongodb to /var/lib/mongodb1 (only helps if the new disk is bigger)
reconfigure mongo to use as db dir the new directory or swap the names with mv commands
start mongo
if everything went fine, mongo started and so on,(check it first!!!) you can delete the old data.
If you have a disk which is the same size so with moving the data you will run into the same problem, if you need larger space then a single disk you should play around with RAID and/or LVM and more disks.
Sorry if my question is nooby, but I can't find any info about it over the net.
My situation is that I have only three files left from my previous DB (they are db_name.0, db_name.1 and db_name.ns), everything else from that system is lost. The DB version was 1.8 and the files were in /data/db.
Now I have a new DB (which is 2.0) on the new system, so I tried to put them to the new DB path, it seems that DB sees them, but doesn't eat (it doesn't say there's something wrong with DB, but records are nil). I know well there was some data. And I have it in app specs from the customer, so I can type manually this data in new DB again, but I'd like to know if there's a way to make this new DB see the old data in these files (not to do the work that had been done). I restarted mongod, tried mongod --repair — nothing. Is there a way to make MongoDB see these files?
And, now I have two pathes, /data/db and /var/lib/mongodb (which one is right to use?).
which one is right to use?
There is no "right one". When you start MongoDB, you have to point it to a DB folder by setting the --dbpath folder. It can really be any folder you want as long as the user who starts the mongod process also has access to that folder.
Is there a way to make MongoDB see these files?
The files you have listed are the default files created when a new DB is created. MongoDB allocates files in advance of needing them. So it's quite possible that these files are indeed empty.