👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Best practices for backing up and restoring datasets in Sanity.io

6 replies
Last updated: Apr 29, 2021
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
production
and create a new datasett called
development
based on the
production
-backup?
Apr 29, 2021, 2:20 PM
1.
sanity dataset export
from the CLI or using the
/export
http 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 import
is 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 production
which by default will be saved to a file called
production.tar.gz
. Then you run
sanity dataset import production.tar.gz development
and this will create a new dataset named
development
if one doesnt exist. If one does exist it will merge the two datasets. For more details look into the flags available on
import
with
sanity help dataset import
Apr 29, 2021, 2:32 PM
• Will the
sanity dataset export
command 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
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
Apr 29, 2021, 2:43 PM
If I export
production
and then import it as
development
, do I then also have to do a graphql-deploy against my new
development
datasett for Gatsby and Sanity Studio to work agains the new
development
datasett?
Apr 29, 2021, 2:46 PM
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
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.

Was this answer helpful?