How to back up your Sanity dataset using CLI or plugins.

2 replies
Last updated: Apr 20, 2024
đź‘‹ Hello, team!
I need to back up my entire Sanity dataset, but I can't find any option to do so through the Sanity UI.
Thanks


help asset-sources
AI Update

You're right that there's no UI option for backing up datasets—this is done through the Sanity CLI. Here's how to back up your entire dataset including assets:

Quick Backup Command

The simplest way to export your entire dataset is:

sanity dataset export production

This creates a production.tar.gz file in your current directory containing all your documents and assets.

You can also specify a custom filename and location:

sanity dataset export production ./backups/backup-2024-01-15.tar.gz

What Gets Included

The export includes:

  • All your documents (published and draft versions)
  • All assets (images, files, videos)
  • Hidden documents used by Studio and plugins

Note: The export doesn't include your schema definition (that lives in your Studio code) or access control settings.

Export Formats

By default, you get a tar.gz archive with documents in NDJSON format plus assets in separate folders. If you only need documents without assets, you can export to NDJSON format instead.

Restoring from Backup

If you ever need to restore, use the import command:

sanity dataset import backup-2024-01-15.tar.gz production

Best Practices

Since Sanity doesn't provide built-in backup storage, you should:

For enterprise plans, there's also a managed Backup feature with retention policies and a Cloud Clone feature for server-side dataset copying without downloading locally.

Make sure you have the Sanity CLI installed (npm install -g @sanity/cli) and are authenticated (sanity login) before running export commands!

You can use the CLI or a plugin like this: https://www.sanity.io/plugins/backups#
As
user C
intimated, there is presently no mechanism inside the Studio to do so.
However:
• The most popular method, and arguably the most straightforward, is using the
CLI to produce an export •
Some people have set up a recurring process through GitHub Actions •
One enterprising individual made sure their offsite storage service supports Sanity ( details on the plugin here: https://www.sanity.io/plugins/backups ) I can't vouch for it because I don't use it but people have discussed using it with success(Sorry, I was in the middle of typing and thought I'd keep going haha...thanks for all the good work you've been putting in!)

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?