0

Using mongodump and mongorestore with in-use encryption, I found out recently that restoring a Mongo database having queryable encrypted fields, regardless the version used (community or entreprise), was not possible.

All documents of a collection with a __safeContent__ field will actually fail to be restored:

$ /usr/bin/mongorestore --nsFrom='db_YMD.*' --nsTo='db.*' /tmp/dump/ [...] preparing collections to restore from [...] reading metadata for db.enxcol_.user.esc from /tmp/dump/db_YMD/enxcol_.user.esc.metadata.json [...] reading metadata for db.user from /tmp/dump/db_YMD/user.metadata.json [...] reading metadata for db.datakeys from /tmp/dump/db_YMD/datakeys.metadata.json [...] dropping collection db.datakeys before restoring [...] dropping collection db.user before restoring [...] restoring db.datakeys from /tmp/dump/db_YMD/datakeys.bson [...] finished restoring db.datakeys (11 documents, 0 failures) [...] restoring db.user from /tmp/dump/db_YMD/user.bson [...] finished restoring db.user (0 documents, 2 failures) [...] Failed: db.user: error restoring from /tmp/dump/db_YMD/user.bson: bulk write exception: write errors: [Cannot insert a document with field name __safeContent__, Cannot insert a document with field name __safeContent__] 

I tried 2 other ways to achieve the backups but to no avail:

  • stopping Mongo/copying+archiving /data/db dir/restarting Mongo => the good part is that the data remains encrypted, however the backup is not fully portable
  • mongoexport/mongoimport => although this technique works, it is not suitable because the data is stored in clear text in the backup file

I did not try the LVM snapshot method as it requires non negligible extra-work to implement.

Could someone confirm my findings? Would you recommend to go with snapshot backups in such case?

1 Answer 1

1

As stated in the official MongoDB documentation, mongorestore has the following limitation: you can't use it with a collection that uses Queryable Encryption.
https://www.mongodb.com/docs/database-tools/mongorestore/#definition

To be noted that QE/CSFLE requires the Enterprise license (AFAIK). So the alternatives are either Atlas, or self-hosted with MongoDB Cloud Manager or Ops Manager. For backup methods for a self-managed deployment, you may refer to the appropriate documentation:
https://www.mongodb.com/docs/manual/core/backups

You might also be interested by this thread from the official forum back in 2023 where the issue is discussed:
https://www.mongodb.com/community/forums/t/restoration-for-encrypted-data-is-not-happening/241848

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.