Duplicating datasets in admin dashboard and using CLI for imports

5 replies
Last updated: May 21, 2024
Is there an easy way to duplicate an entire dataset in the admin dashboard? Hoping to duplicate Contentful behavior where you can easily delete and spin up a staging env from production.
AI Update

Unfortunately, there isn't a one-click "duplicate dataset" button in the Sanity admin dashboard at manage.sanity.io like you might find in Contentful. However, Sanity offers several approaches depending on your plan tier:

Enterprise Plan: Cloud Clone

If you're on an Enterprise plan, you get access to Cloud Clone as part of Advanced Dataset Management. This is the closest equivalent to Contentful's behavior - it duplicates datasets entirely in the cloud without needing to download/upload data. You can easily spin up a staging environment from production and delete/recreate as needed.

Cloud Clone also comes with Hot Swap, which lets you create aliases that can seamlessly switch between datasets - super useful for testing migrations or validating changes before going live.

To access these features, you'll need to contact Sanity's sales team about upgrading to an Enterprise plan.

For Other Plans: CLI or Plugin

If you're not on Enterprise, you have two main options:

1. CLI Export/Import (all plans)

The standard approach uses the Sanity CLI:

# Export from production
sanity dataset export production production-backup.ndjson

# Import to staging
sanity dataset import production-backup.ndjson staging --replace

The --replace flag will clear the target dataset first, giving you that "delete and spin up fresh" workflow you're looking for.

2. Cross Dataset Duplicator Plugin (all plans)

This community plugin by Simeon Griggs adds a GUI within Sanity Studio for migrating documents and assets between datasets. It's more user-friendly than the CLI and doesn't require technical knowledge, though it's still not quite as streamlined as a dashboard button.

Install it with:

npm i @sanity/cross-dataset-duplicator

While Sanity's approach requires a bit more manual work compared to Contentful's dashboard UI, the CLI method is reliable and the Enterprise features provide the most seamless experience if dataset duplication is a frequent need in your workflow.

The only two ways to create a dataset are via the CLI or the HTTP API. There is some tooling for cloning and swapping datasets, but those are only available on Enterprise plans.
I should also note that we have an endpoint for exporting your dataset, but not for importing (unless you want to do it all through mutations).
Thanks, that's super helpful info! There's the
CLI NDJSON
import, right? Is the export supporting the same format?
The export through the CLI will output a gzipped tarball. There are some examples here .
Oh awesome, just tried it. Spits out
.ndjson
so should be easy to import with the CLI right away!
Excellent!

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?