See Sanity in action 👀 Join us for a live product demo + Q&A →

Restoring previous versions of documents in a dataset

6 replies
Last updated: Feb 2, 2023
Is there a way to restore an entire dataset to what it was on a previous date or undo the most recent change on all documents? Asking for a friend... 😬
Feb 1, 2023, 11:32 PM
Unfortunately, no, you can’t rollback an entire dataset. You could probably use the History API to programmatically revert documents to a previous
_rev
, though.
Feb 1, 2023, 11:35 PM
That’s what I was afraid of. Guess I shouldn’t have put off that “backup sanity to s3” task for so long lol. Thanks for the tip on the history API!
Feb 1, 2023, 11:36 PM
user M
Should I be able to set a
_rev
using the JS client? Something like:

    {
      id: doc._id,
      patch: {
        set: { _rev: doc._rev },
      },
    }

Feb 2, 2023, 12:22 AM
More importantly: if I set an old revision would that restore images on the document?
Feb 2, 2023, 12:31 AM
I worked it out by watching the network tab in the studio. Thanks again for the tip on the history api, that worked wonders.
For anyone who happens to see this: you pull the version of the document you want via the history api, then you can use
.createOrUpdate()
from the js client with the entire document from the history api as the payload.
Feb 2, 2023, 1:21 AM
Glad you got it sorted out!
Feb 2, 2023, 6:16 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in