Search code examples
backuprestoresanity

Sanity.io backup and restore (or auto-saving doc IDs)


Question #1: is it possible to restore deleted items from backup in Sanity.io?

To my understanding, restoring a backup is done by exporting all documents from a dataset's history, and importing it.

  1. Restore - there's one way to do it: https://www.sanity.io/docs/importing-data.
  2. Export - there're two ways to export data:
    1. Export all currently-existing-data: https://www.sanity.io/docs/export.
    2. Export one historical document by its ID: https://www.sanity.io/docs/history-api.

IDs of deleted items do not appear in currently-existing-data (because they are deleted, duh), and without them, I can't get historical documents.

Also, there's a Gotcha section saying:

Gotcha

Current Access Control means if you're able to access the document today, you'll be able to access all the previous revisions of the document.

Question #2: if restoring deleted items from backup is NOT possible due to those missing document IDs - is there a way to automatically save all document IDs (either every hour or whenever a change occurs)?

I guess that if there's a mechanism that also saves the last time an ID was seen, you can also know more or less its deletion time...


Solution

  • I saw that the Sanity.io project has a webhook that gets triggered when changes occur (under 'Settings' tab --> 'API' sub-tab). I guess this could be set to call a service that gets all documents and save their ID with the current timestamp.