Restoring MongoDB database from physical files

Issue

My hard drive cannot boot into Ubuntu 18.04 Desktop any more (I suspect that the UI doesn't load but everything else should work fine). It will take too much time to analyze what went wrong, so I would like to back up all my physical MongoDB data located in /var/lib/mongodb and have it restored to another PC.

I started booting into Ubuntu live but could only find information to backup/restore MongoDB databases using a MongoDB service like "mongodump and mongorestore"; these cannot be applied here. But is it possible to copy the folder /var/lib/mongodb to a USB drive and then restore it to the same location in a new PC? Are there any permission commands that need to be run?

Similar to what MySQL provides here

5

1 Answer

In answer to the question: yes. The official backup/restore document calls it "a cold backup" and has this to say:

Back Up with cp or rsync

If your storage system does not support snapshots, you can copy the files directly using cp, rsync, or a similar tool. Since copying multiple files is not an atomic operation, you must stop all writes to the mongod before copying the files. Otherwise, you will copy the files in an invalid state.

Backups produced by copying the underlying data do not support point in time recovery for replica sets and are difficult to manage for larger sharded clusters. Additionally, these backups are larger because they include the indexes and duplicate underlying storage padding and fragmentation. mongodump, by contrast, creates smaller backups.

  • you need to stop mongo

And you can make a backup with ...

  • rsync -vahP /var/lib/mongodb/ /media/backup/

    for a backup to a local directory or

  • rsync -vahP /var/lib/mongodb/ {user}@{url}:/{dir}/

    for a backup to a remote system

Restoring: stop mongo and switch the 2 locations.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like