How to export and re-import Sanity data for different projects/users?
Yes. Export the dataset to a .tar.gz file with the Sanity CLI, then import that file into a dataset in another project (or the same one). The archive holds your documents and asset files. Your schema lives in your Studio code, so you deploy that separately for the new project.
1. Export the dataset
npx sanity@latest login
npx sanity@latest datasets export production production.tar.gz- The first argument is the dataset and the second is the output file. If you leave either out, the CLI asks for it.
- Add
--project-id <id>to export from a project other than the one configured in your current folder. - The archive contains
data.ndjson(every document, one per line),assets.json, andimages/andfiles/folders with the binaries. All asset documents are included, even ones nothing references. - Useful flags:
--no-drafts(published documents only),--types post,author(only some document types),--no-assets(skip the binaries),--mode cursor(faster for large datasets, but can miss edits made while the export runs). - Don't use
--rawwhen moving data to another project or dataset. A raw export keeps the original asset references, and importing it elsewhere fails with "Asset … references a different project ID/dataset". To fix this, export again without--raw(details).
Exports count toward your API usage. See Export a dataset.
2. Create the target project and dataset
Create the new project, then create the dataset that will receive the data:
npx sanity@latest datasets create production --project-id <new-project-id>3. Import the archive
npx sanity@latest datasets import production.tar.gz production --project-id <new-project-id>- Tarballs keep asset references intact, so they're the format to use when migrating. References are added as weak first and made strong once every document exists, so the order of documents doesn't matter.
- If documents with the same
_idalready exist, the import fails. Add--replaceto overwrite them, or--missingto create only the documents that don't exist yet. --allow-failing-assetslets the import continue when an asset can't be fetched.--allow-assets-in-different-datasetis a rare override for asset references that point to another dataset.- In CI, pass a token with
-t <token>.
See Importing data and the datasets CLI reference, or run npx sanity@latest datasets import --help.
4. Point the app at the new project
Configure the Studio and frontend copies with the new project ID and dataset, and deploy them. The new project has its own members and access settings.
Related options
- Copy within the same project (Enterprise): Cloud Clone copies a dataset on Sanity's infrastructure instead of downloading and uploading it. Run
npx sanity@latest datasets copy production staging, and add--skip-historyto speed it up. It only works inside a configured project, so use export/import to move data to a different project. See Cloud Clone. - Backups: certain Enterprise plans include daily dataset backups stored offsite by Sanity. You turn them on per dataset with
sanity backups enable <dataset>, and they're restored withsanity datasets import <file> <dataset> --replace. A restore doesn't remove documents that aren't in the backup. On other plans, schedule your owndatasets exportruns and keep the files somewhere safe. See Backups.
Show original thread2 replies
Was this answer helpful?
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.