Best practices for backing up and restoring datasets in Sanity.io
6 replies
Last updated: Apr 29, 2021
F
Sanity datasets and backup
• Whats the best way to backup a dataset in Sanity?
• Can I do it from the dashboard?
• How about automatic scheduled backups? Like say once a week?
• How do I restore from an backup?
• Can I backup a dataset called
• Whats the best way to backup a dataset in Sanity?
• Can I do it from the dashboard?
• How about automatic scheduled backups? Like say once a week?
• How do I restore from an backup?
• Can I backup a dataset called
productionand create a new datasett called
developmentbased on the
production-backup?
Apr 29, 2021, 2:20 PM
H
1.
3. You could write a script that runs either of the above commands, but per my knowledge there is no automation other than what you build yourself
4.
and this will create a new dataset named
sanity dataset exportfrom the CLI or using the
/exporthttp api https://www.sanity.io/docs/export 2. I do not believe so
3. You could write a script that runs either of the above commands, but per my knowledge there is no automation other than what you build yourself
4.
sanity dataset importis the easiest way. You can also use a client library, though that has some pitfalls: https://www.sanity.io/docs/importing-data 5. Yes. Run
sanity dataset export productionwhich by default will be saved to a file called
production.tar.gz. Then you run
sanity dataset import production.tar.gz development
developmentif one doesnt exist. If one does exist it will merge the two datasets. For more details look into the flags available on
importwith
sanity help dataset import
Apr 29, 2021, 2:32 PM
F
• Will the
• Does that mean that I have to find some external cloud service to store my backups?
sanity dataset exportcommand give me all data, including assets like images and files thats uploaded in the dataset?• What about the schema, is that a part of the export?
• Does that mean that I have to find some external cloud service to store my backups?
Apr 29, 2021, 2:35 PM
H
1. the export will include all user-generated documents, images and files, but will not include system documents that Sanity itself uses to function like custom access control ( https://www.sanity.io/docs/access-control#ce4a077926aa ) to my knowledge. 2. The schema isnt part of the dataset in the strictest sense. The schema is a concept that lives in the Studio and is how your Studio filters what documents are allowed to enter your dataset. Since it isnt part of the dataset it will therefore not be included in the export
a. Sidenote: Since only the Studio enforces your schema, you could also sidestep it by creating documents with the API or CLI that dont follow the schema. Be aware of this when creating documents this way
3. Yes, or some equivalent service according to your risk profile and data processor agreement
a. Sidenote: Since only the Studio enforces your schema, you could also sidestep it by creating documents with the API or CLI that dont follow the schema. Be aware of this when creating documents this way
3. Yes, or some equivalent service according to your risk profile and data processor agreement
Apr 29, 2021, 2:43 PM
F
If I export
productionand then import it as
development, do I then also have to do a graphql-deploy against my new
developmentdatasett for Gatsby and Sanity Studio to work agains the new
developmentdatasett?
Apr 29, 2021, 2:46 PM
H
I dont know, I dont use graphql in my projects. 🙂 I would guess so, but you should try and see what needs to happen. You could also see if there is some information here that is helpful: https://www.sanity.io/docs/cli-graphql
Apr 29, 2021, 2:50 PM
F
Thank you! I will try 🙂
Apr 29, 2021, 2:54 PM
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.