At the time of writing this, there didn't seem to be a simple way of backing up data from Sanity.io. I thought there would have been a simple UI in the Admin backend that allowed you to download a compressed data version, but sadly, there is not.
After a quick investigation, I discovered that the easiest way to do this is via the Sanity CLI.
The Sanity CLI allow you to export your Dataset to a local file using the command line.
Steps to backup your data
1. Install the Sanity CLI (if not already installed)
2. Login to Sanity
Ensure that you are logged into Sanity with the correct credentials:
3. Export the Dataset
Use the sanity dataset export command to export your dataset:
Replace the <dataset-name>
with the name of your dataset (e.g., production
) and <output-folder>
with the folder where the exported file should be saved.
This will create a .tar.gz
file containing your dataset in the specified folder.
Restore the Dataset (if needed)
If you need to restore the dataset after making changes, use the sanity dataset import
command:
Extra information
Make sure that you have sufficient permissions for exporting datasets. Large datasets might take some time to export.
Automate backups
You could set up a cron job or script to periodically back up your dataset.
Verify exports
After exporting your data, you can verify the .tar.gz
file by extracting it:
Once you have a backup, you can more confidently make changes to your dataset.