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/dbdir/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?