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 https://stackoverflow.com/questions/484750/restoring-mysql-database-from-physical-files

  • How easy/difficult, and the tools used would depend on the type of problem you have. If the drive is failing for example; the recovery is different to just a logical/corruption error - ie. if faulty/failing drive normal copy may not work & recovery maybe your only choice. Viewing files via directory shows only the directory itself, and problems may only occur once you try copying the contents of those filenames (ie. data itself). It may help if you better clarify your issue.
    – guiverc
    Jan 11 at 21:30
  • @guiverc I added the details. I think only the UI part of Ubuntu is failing.
    – Chiggiddi
    Jan 11 at 21:34
  • You haven't said if you're talking Ubuntu 18.04 LTS Desktop, or Server.. but your use of UI makes me think you're talking desktop (GUI) and thus I'd just boot normally & login via text terminal (not GUI) and copy the files that way. If you have a lot of config issues, I'd next try booting to runlevel 1 first (recovery type tools; sorry I use generic linux tools, not Ubuntu ones for recovery, thus my usage of runlevel 1)
    – guiverc
    Jan 11 at 21:39
  • @guiverc copy the files is not a problem, but what is the correct way to restore physical data for mongodb? I cannot simply use mongorestore as this would need a mongodb file which I don't have; I only copied the folder and file structure found in /var/lib/mongodb
    – Chiggiddi
    Jan 11 at 21:51
  • @Rinzwind yes this is a possibility, but is it possible to restore mongodb by the physical files and not using mongodump via command line if mongodb service has issues.
    – Chiggiddi
    Jan 11 at 21:55

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.