How to backup Sanity Studio CMS content using the CLI.
Yes, absolutely! Sanity provides several ways to backup your content, with the most common being the CLI export command.
Using the CLI to Export Your Dataset
The easiest way to backup your content is using the Sanity CLI:
sanity dataset export productionThis creates a production.tar.gz file containing all your documents and assets. You can also specify a custom filename:
sanity dataset export production ./backups/backup-2024-01-15.tar.gzWhat's Included in the Export
The export includes:
- All your documents (posts, pages, etc.)
- All assets (images, PDFs, files)
- Hidden documents used by Studio and plugins
It does not include your schema definition (that lives in your Studio code) or access control settings.
Exporting Without Assets
If you only need the document data (not images/files), you can export to NDJSON format:
sanity dataset export production backup.ndjson --no-assetsRestoring from a Backup
To restore or import a backup:
sanity dataset import production.tar.gz productionThis merges the backup content with your existing dataset. Always test imports on a development dataset first!
Automated Backup Strategies
Since Sanity doesn't store backups for you, consider setting up automated backups using:
- GitHub Actions - You can use this guide for automated Studio backups with GitHub Actions to schedule regular exports
- Scheduled scripts - Run the export command via cron jobs or CI/CD pipelines
- Cloud storage - Store exports in AWS S3, Google Cloud Storage, or similar services
Enterprise Backup Features
If you're on an Enterprise plan, Sanity offers managed backup features with:
- Automatic backup scheduling
- Retention policies
- Server-side dataset cloning (Cloud Clone)
- No need to download data locally
Best Practice Tip
Always export your dataset before running content migrations:
# Backup first
sanity dataset export production backup-before-migration.tar.gz
# Run your migration
sanity migration run your-migration
# Restore if needed
sanity dataset import backup-before-migration.tar.gz productionThe CLI export/import workflow is reliable and gives you complete control over your content backups!
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.