How to restore entire dataset to previous date or undo recent changes?
š¬ I feel your friend's pain! Unfortunately, Sanity doesn't have a built-in way to do a full dataset rollback to a previous date or bulk-undo across all documents.
What Sanity DOES offer:
Document History lets you restore documents one at a time by viewing their revision history and rolling back to a previous version. You can access this through the document status indicator at the bottom of the editor or via the contextual menu (ellipsis icon) ā "History".
Important limitations:
- Retention periods vary by plan:
- Free: 3 days
- Growth: 90 days
- Enterprise: 365 days (customizable)
- After the retention period, older revisions are permanently deleted (though the latest published/draft versions remain)
For bulk restoration:
If your friend needs to restore multiple documents, they'd need to use the History API programmatically. You could:
- Query the history for each document
- Retrieve the revision from your target date (using the
_revproperty) - Use the JavaScript client's
createOrReplace()method to restore each document
This would essentially be a custom script to loop through documents and restore them individually. Not ideal, but it's the available path.
Prevention tip: For future peace of mind, consider exporting dataset backups regularly using the sanity dataset export CLI command. That way you have a safety net outside of the built-in history retention!
Show original thread6 replies
Sanity ā Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.