MongoDB: Restoring db using data from dbPath

631 views
Skip to first unread message

Jehanzeb Malik

unread,
Feb 19, 2018, 5:14:59 PM2/19/18
to mongodb-user
**Backstory:**

I had hosted mongodb on a server from IBM's bluemix. Today the link went down in the region of my server. They restored the link but there were other issues now. My VSI's `filesystem` is now in a `read-only` state. Which seems like is due to inconsistencies in the root filesystem. They tried to boot our VSI into a rescue kernel and run a filesystem check (fsck). Unfortunately that didn't fix it. Bottom line is that I can not run any service on my server atm.

**Issue:**

I need to access my db to host it on another server. The last backup that I have is from 3 weeks back. I need latest backup and I can not create new backup file as service cannot run on a `read-only` filesystem.

**Question:**
I can access the files on dbpath and have already made a backup of those files on my local machine. Is there some way I can use these files to up another instance of mongodb?

**What I tried:**
I tried creating an instance of mongodb on my local machine. I accessed the shell. Then replaced the files in dbpath with the files which I backed-up from server. In shell i ran `db.repairDatabase()`, hoping that it might work. But nope.

Any help in this regard would be highly appreciated.


***Edit***

In shell after `db.repairDatabase()` I tried running `show dbs;`. This was the response.

    2018-02-20T02:19:35.090+0500 E QUERY    [thread1] Error: listDatabases failed:{
    "ok" : 0,
    "errmsg" : "unable to open cursor at URI statistics:table:collection-0--2640332284129588306. reason: No such file or directory",
    "code" : 43
    }

Kevin Adistambha

unread,
Feb 25, 2018, 8:24:12 PM2/25/18
to mongodb-user

Hi

I can access the files on dbpath and have already made a backup of those files on my local machine. Is there some way I can use these files to up another instance of mongodb?

Yes. You should be able to start up a new mongod process by specifying the dbpath directory to those copied data files. See Specify a Data Directory for details.

I tried creating an instance of mongodb on my local machine. I accessed the shell. Then replaced the files in dbpath with the files which I backed-up from server.

I doubt that this will work. From my understanding, you spin up a new mongod, then replaced its dbpath content. If you do this replacement while the server is running, it will put the database in an inconsistent state. If you do this replacement while the server is not running, then you’re overlaying the dbpath of two different deployments into one.

Instead of overwriting, it’s best if you specify mongod --dbpath <path_to_the_backup_dbpath>.

“errmsg” : “unable to open cursor at URI statistics:table:collection-0—2640332284129588306. reason: No such file or directory”,

This error was caused by WiredTiger expecting for a file to exist, but it doesn’t. Could you check if your backup contains the file with a name such as collection-0--2640332284129588306.wt? If not, then I’m afraid you have an incomplete backup. Unfortunately, if the incomplete backup or data corruption was caused by the hosting service, there’s very little any database can do to recover.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages