How to retrieve a previous dataset in Sanity.io using the History API.
12 replies
Last updated: Jun 13, 2022
L
Hello,Does sanity keep dataset backups somewhere or is it something that needs to be done manually?
Is there a way to retrieve a dataset as of yesterday?
I have mistakenly overwritten the production dataset with the development one which is few months old, and I cannot find any option on the website to restore a previous dataset. (project is on team plan if that helps)
Best,
User
Is there a way to retrieve a dataset as of yesterday?
I have mistakenly overwritten the production dataset with the development one which is few months old, and I cannot find any option on the website to restore a previous dataset. (project is on team plan if that helps)
Best,
User
Jun 10, 2022, 9:07 AM
K
You’d have to do it manually with the export functionality I’m afraid. 😞
Jun 10, 2022, 9:16 AM
K
Maybe a support engineer can help you though.
Jun 10, 2022, 9:17 AM
L
Thanks User, how do I reach a support engineer?
Jun 10, 2022, 9:18 AM
K
Someone will reach out to you I guess.
Jun 10, 2022, 9:31 AM
L
Thanks 🙂 I'll wait
Jun 10, 2022, 9:32 AM
S
Hi User,This might be a case we cannot solve
😔. We generally recommend folks adopt their own backup routine; either by exporting their dataset or by making use of our cloud dataset cloning (for enterprise customers).However since you didn't delete the dataset in this case, it might be possible to rework it with information from the
History API if you feel comfortable writing a script. If you wish to explore that route, please let us know if we can assist in any way.
😊
😔. We generally recommend folks adopt their own backup routine; either by exporting their dataset or by making use of our cloud dataset cloning (for enterprise customers).However since you didn't delete the dataset in this case, it might be possible to rework it with information from the
History API if you feel comfortable writing a script. If you wish to explore that route, please let us know if we can assist in any way.
😊
Jun 10, 2022, 5:46 PM
L
Hi
Does the history gets preserved even if I ran a restore with the
user J
, yep I've written sanity scripts before so I might get down to that route. Does the history gets preserved even if I ran a restore with the
--replaceflag? From a quick check on the backend everything seem to be dated back to April, some documents even on February with the exception of new documents which have been preserved
Jun 10, 2022, 6:58 PM
S
Yes, history should be preserved via the transaction log.You can confirm this by running the command below, replacing these variables:
•
•
AUTH_TOKEN(obtained via
sanity debug --secretsin the CLI)•
PROJECT_ID•
DATASET_NAME•
DOCUMENT_ID(any
IDof a document that was replaced)
curl -H "Authorization: Bearer <AUTH_TOKEN>" "https://<PROJECT_ID>.<http://api.sanity.io/v2021-06-07/data/history|api.sanity.io/v2021-06-07/data/history>/<DATASET_NAME>/transactions/<DOCUMENT_ID>?excludeContent=true"
Jun 13, 2022, 9:47 AM
L
omg, it works
Jun 13, 2022, 10:22 AM
L
Life saver! Thank you very much!!!
Jun 13, 2022, 10:22 AM
S
yay
Jun 13, 2022, 10:45 AM
S
Wonderful we were able to help you out!
Jun 13, 2022, 10:46 AM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.