How to Copy a Sanity Production Dataset to a Development Environment

Spread the love

Introduction

When managing multiple environments in Sanity, it’s essential to have a separate development environment for testing without affecting production data. In this guide, we’ll walk through how to export a Sanity production dataset and import it into a development environment using the command line on an Ubuntu machine.

Following these steps will ensure that your development environment mirrors production, allowing safe testing and debugging.

Step-by-Step Guide to Copy a Sanity Dataset

Step 1: Export the Production Dataset

To create a backup of the production dataset, use the following command:

Bash
sanity dataset export production production-backup.tar.gz

This command will:

  • Export the production dataset.
  • Export the production dataset.

Save it as a file named production-backup.tar.gz in the current directory.

Step 2: Create a New Development Dataset

Before importing the production backup, create a new dataset for development:

Bash
sanity dataset create development

This will create a development dataset, which will serve as a clone of the production data.

Step 3: Import the Backup into Development

Once the development dataset is created, import the backup file into it:

Bash
sanity dataset import production-backup.tar.gz development

This command will:

  • Load all documents from production-backup.tar.gz into the development dataset.

Step 4: Verify the Import

To confirm that the dataset was imported successfully, list all available datasets:

Bash
sanity dataset list

This should display both the production and development datasets.

(Optional) Step 5: Clean Up the Backup File

If you no longer need the exported backup file, you can delete it to free up space:

Bash
rm production-backup.tar.gz

Final Summary

Here’s a quick recap of all the commands:

Bash
sanity dataset export production production-backup.tar.gz
sanity dataset create development
sanity dataset import production-backup.tar.gz development
sanity dataset list
rm production-backup.tar.gz  # Optional cleanup

By following these steps, you can safely clone your production dataset into a development environment, ensuring a stable testing setup without risking live data.

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com