Skip to main content
When you need to move data from an old volume to a new one, the simplest approach is to mount both volumes into a single sandbox and copy the files across. This page walks through a script that does exactly that: it spins up a sandbox from the base template, mounts a source and a destination volume, and copies all data from source to destination.
  • The source volume must already exist. If it doesn’t, the script fails.
  • The destination volume is reused if it already exists, or created if it doesn’t.

Prerequisites

You need an E2B account with your API key set as E2B_API_KEY in your environment, and the E2B SDK installed.

The script

The script first resolves both volumes by name, connecting to the source and connecting to (or creating) the destination. It then mounts both into a sandbox and uses rsync to copy the data across. Reading the volume type from the token is optional, but it’s a handy sanity check that you’re copying between the volumes you expect. Save this as copy-volume.mts (JavaScript & TypeScript) or copy_volume.py (Python):

Usage

Run the script with the source and destination volume names. For example, to copy everything from prod-data into prod-data-backup:
On success it prints a listing of the destination so you can confirm the data landed. The sandbox is always shut down afterward, but both volumes (and their data) persist.