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?
AI Update

Great questions about backing up your Sanity datasets! Let me walk you through the different options available.

Best way to backup a dataset

The best approach depends on your plan level:

For Enterprise plans: Sanity offers a managed backup feature that automatically creates daily backups of your dataset. This is the most robust solution with automated scheduling and retention policies (daily backups for 365 days, weekly backups for an additional 2 years).

For all plans: You can manually export your dataset using the Sanity CLI:

sanity dataset export production

This creates a .tar.gz file containing all your documents and assets in NDJSON format.

Can you do it from the dashboard?

No, backups cannot be created directly from the dashboard. You'll need to use the Sanity CLI for both the managed backup feature (Enterprise) and manual exports (all plans).

Automatic scheduled backups

Enterprise plans only: Once you enable the backup service via CLI, Sanity automatically performs daily backups:

sanity backup enable production

Your first backup will be available within 24 hours, and the service continues running daily after that.

For other plans: You'll need to set up your own automation. A popular approach is using GitHub Actions to schedule regular exports and store them as artifacts or in cloud storage (S3, Google Cloud Storage, etc.).

How to restore from a backup

Use the sanity dataset import command:

sanity dataset import backup-2024.tar.gz production

Important gotcha: If you're importing into a different dataset than the backup originated from, add the --allow-assets-in-different-dataset flag.

For detailed restoration steps, check out the guide on restoring a deleted dataset from a backup.

Creating a development dataset from production backup

Yes, absolutely! This is a common workflow. Here's how:

  1. Export your production dataset:
sanity dataset export production production-backup.tar.gz
  1. Create a new development dataset (if it doesn't exist):
sanity dataset create development
  1. Import the backup into development:
sanity dataset import production-backup.tar.gz development --allow-assets-in-different-dataset

The --allow-assets-in-different-dataset flag is required when importing across different datasets.

Enterprise alternative: Cloud Clone

If you're on an Enterprise plan, there's also Cloud Clone which duplicates datasets directly in Sanity's cloud infrastructure without downloading anything locally - much faster for large datasets!

What's included in backups?

Backups contain:

  • All documents (including hidden ones used by Studio and plugins)
  • All assets (images and files)

Not included:

  • Schema definitions (these live in your Studio code)
  • Comments
  • Document history/revision timeline

Hope this helps! The CLI export approach works for everyone, while the managed backup feature provides enterprise-grade automation and retention policies.

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
• 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?
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
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?
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
Thank you! I will try 🙂

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.

Was this answer helpful?