Backup/restore a partition

I’m wondering what strategies there are for backup/restoring data for a given partition. If a syncing Realm mobile app has a separate partition for each user and the user deletes something they wish they hadn’t or there is a bug in the app that corrupts data, how can you restore the data to a previous state? On a mobile device the app can make copies of the user’s data periodically. In the event of disaster, I can get the user’s backup and restore the data. Is there a better alternative?

@Nina_Friend Well you could use Realm Sync! :smiley:

The data is stored in MongoDB Atlas so if the client-side Realm is corrupted you could re-download the data from Atlas.

The Realm client doesn’t has an undo functionality but you could implement some sort of history or opLog yourself - say to store the last ten edits. And then rollback if needed. You could do this on the client if you are non-sync or you could also do this on the serverside by tailing the MongoDB oplog.

1 Like

I am using a sync Realm. If the errant delete or corruption happens on the client then sync happens and I have the corruption in Atlas. I don’t see how I can re-download from Atlas if sync is going on.

Is there some document that shows how to use the opslog on the server side to rollback changes for a particular partition instead of the whole database?

I wouldn’t call a delete a corruption - that is a CRUD operation that your app allowed but it sounds like you want to validate that delete against some business logic. In that case perhaps a database trigger might work?
https://docs.mongodb.com/realm/triggers/database-triggers/

If you need something more custom you can tail the MongoDB opLog -called changestreams. see here:
https://docs.mongodb.com/manual/changeStreams/