# GreptimeDB Export/Import v2: Resumable Transfers and Up to 180x Faster Migration for 100K Logical Tables

Source: https://greptime.com/blogs/2026-12-02-greptimedb-export-import-v2

Two things hurt most in a large data migration. The first is a job that dies halfway through, leaving you unsure which data has already been written and where to pick up. The second is a huge number of small tables: with 100,000 logical tables of a few dozen rows each, the fixed cost of creating a file, sending a request, and running DDL for every single table is enough to blow the whole migration window.

In GreptimeDB, the new `export-v2` and `import-v2` commands target both problems:
* **Time-based chunking with resumable transfers**: A large job is split into time windows. Each time a chunk or an import task finishes, its progress is written to the snapshot manifest or to the CLI's local state file. Rerun the same command after an interruption, and completed work is skipped automatically.
* **Much lower small-table overhead for Metric Engine**: The exporter can run one shared scan per physical table and pack the Parquet data of many small tables into a single object, cutting I/O and request counts sharply.

> **Version note**: The commands in this article are based on **[v1.3.2](/blogs/2026-12-01-greptimedb-v1-3-2-release)**, released on November 30. If you are still on v1.3.0 or v1.3.1, we recommend upgrading straight to v1.3.2, which includes a number of fixes backported since v1.3.0.

---

## How It Works: Snapshots, Chunks, and Resume Progress

The old `cli data export / import` could already filter data by time, use `COPY` with Parquet, and read from and write to object storage. What it lacked was task splitting and progress tracking. v2 adds **time-based chunking** and **persistent progress** on top of that, and fills in snapshot management: verify, list, and delete.

v2 splits the work between the CLI and the GreptimeDB servers. The CLI schedules the job and records progress; the source and target servers read and write the snapshot storage directly through `COPY DATABASE`.

This also fixes a long-standing problem in the old tool. The old `output_dir` was resolved separately by the CLI and by the server, so when the two ran on different machines, the same path could point to two completely different local directories. v2 requires the snapshot location to be a standard URI such as `file://` or `s3://`, and the URI alone determines both the storage backend and the path.

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/flow-storage.png" alt="The CLI schedules export and import and records progress; the source and target servers read and write the snapshot directly through COPY DATABASE at a file:// or s3:// URI" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

A complete snapshot contains a manifest file `manifest.json`, the schema definitions (`schema/`), and the data itself (`data/`):
* `manifest.json`: records the time range, the completion status of each chunk, and the list of data files. `import-v2` builds its restore tasks from it.
* `schema/`: holds the schema list (`schemas.json`) and the CREATE statements (`ddl/`).
* `data/`: stores data files in one directory per schema and chunk.

Here is the layout of a regular snapshot with 2 schemas split into 3 chunks (by default, each table gets its own file; with the `packed` mode described later, small tables are merged into pack objects and the layout differs):

```text
snapshot/
├── manifest.json
├── schema/
│   ├── schemas.json
│   └── ddl/
│       ├── logs.sql
│       └── public.sql
└── data/
    ├── public/
    │   ├── 1/host_metrics.parquet
    │   ├── 2/host_metrics.parquet
    │   └── 3/host_metrics.parquet
    └── logs/
        ├── 1/app_logs.parquet
        ├── 2/app_logs.parquet
        └── 3/app_logs.parquet
```

### Time Window Chunking and Resume

Suppose we export data from October 1 to October 4. With `--chunk-time-window 1d`, the job is split into three contiguous intervals, `[10/1, 10/2)`, `[10/2, 10/3)`, and `[10/3, 10/4)`, and each table is filtered by its own time index. As the figure shows, if the first two chunks have finished and the job fails, the rerun only exports the third chunk:

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/chunk-resume.png" alt="A time range split into three daily chunks; after the first two complete, a rerun exports only the third" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

Chunking requires both `--start-time` and `--end-time`. Without a window size, the whole time range is processed as a single chunk, and the file size depends on how much data falls in that range.

Once the data is chunked, a long export of a single schema can run in parallel, and the importer can split work into parallel tasks at `schema × chunk` granularity (for example, 2 schemas × 3 chunks = 6 data import tasks):

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/concurrency.png" alt="Import tasks split by schema × chunk: 2 schemas × 3 chunks give 6 parallel data import tasks" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

Where progress is recorded, and at what granularity work is retried, depends on the phase:

| Phase | Where progress is recorded | Resume granularity |
| :--- | :--- | :--- |
| **Data export** | `manifest.json` in the snapshot | **A whole time chunk** (marked complete only after every selected schema in that chunk is exported) |
| **Import DDL** | The CLI's local `import state` | **The whole DDL phase** (checkpointed after all CREATE statements succeed) |
| **Import data** | The CLI's local `import state` | **A single `schema / chunk` task** |

**Practical details for resuming:**
1. **Keep parameters and state files unchanged**: Resume depends on the original snapshot and the CLI's local `import state`. Keep both, and use the same time range, window size, and format as the previous run.
2. **Retries after partial writes**: Progress is only recorded at the granularity above, so if an import task fails after writing some rows, the retry runs the whole task again.
3. **Watch out for false timeouts**: After an interruption, confirm that the server has actually finished the previous request before rerunning. An HTTP timeout on the client does not mean the server has stopped writing.

---

## Walkthrough: A Complete Migration

We start with two standalone instances on one machine to run the full flow: the source HTTP address is `127.0.0.1:4000`, the target is `127.0.0.1:4100`, and we migrate the `public` schema.

### 1. Allow access to the local directory
In standalone mode, `COPY` can only access `<data_home>/copy` by default. We put the snapshot under `/tmp/greptime-snapshots`, so create that directory first, then add it as `copy_root` in the configuration of both the source and the target:

```toml
[storage]
copy_root = "/tmp/greptime-snapshots"
```

### 2. Run a chunked export
Split three days of data into 3 daily chunks, with a concurrency of 2:

```bash
greptime cli data export-v2 create \
  --addr 127.0.0.1:4000 \
  --to file:///tmp/greptime-snapshots/oct-demo \
  --schemas public \
  --start-time 2026-10-01T00:00:00Z \
  --end-time 2026-10-04T00:00:00Z \
  --chunk-time-window 1d \
  --chunk-parallelism 2
```
If the export is interrupted, run the same command again to continue. Do **not** add `--force` unless you really want to wipe the old snapshot and start over.

### 3. Verify the snapshot and preview the import plan
After the export finishes, verify the snapshot first, then preview the import with `--dry-run`:

```bash
# Check that the snapshot structure matches the manifest
greptime cli data export-v2 verify \
  --snapshot file:///tmp/greptime-snapshots/oct-demo

# Preview the import plan (no tables created, no data written, no state file)
greptime cli data import-v2 \
  --addr 127.0.0.1:4100 \
  --from file:///tmp/greptime-snapshots/oct-demo \
  --dry-run
```

`verify` checks that the files match `manifest.json`: whether every chunk is complete, whether the schema and DDL files exist, whether any data files are missing or unexpected, and whether object lengths and byte ranges in the packed index are valid. (It does not compare data values row by row, and it does not compute a full content checksum.) If verification reports unfinished chunks, rerun the same `export-v2` command to finish them. A rerun skips chunks already marked complete, so if a completed chunk has missing or damaged files, export again to a new snapshot path or with `--force`.

### 4. Import into the target
Once everything checks out, start the import:

```bash
greptime cli data import-v2 \
  --addr 127.0.0.1:4100 \
  --from file:///tmp/greptime-snapshots/oct-demo \
  --state-path /tmp/greptime-import-oct.state \
  --task-parallelism 2
```

Without `--state-path`, the state file is stored under `~/.greptime/import_state` by default. If the import fails, rerun it with the same state file to resume.

**Once the import fully succeeds, the CLI deletes the state file.** If you run the same import command again afterwards, the CLI treats it as a brand-new import. The DDL uses `IF NOT EXISTS` and will not fail, but the data is written a second time, and append-mode tables end up with duplicate rows.

### 5. Validate the result and manage snapshots
After the import, list the databases and tables on the target:

```bash
curl -sS -X POST "http://127.0.0.1:4100/v1/sql" \
  --data-urlencode "sql=SHOW DATABASES"

curl -sS -X POST "http://127.0.0.1:4100/v1/sql?db=public" \
  --data-urlencode "sql=SHOW TABLES"
```
To be safe, also spot-check row counts, earliest and latest timestamps, and key business aggregates on a few core tables.

For routine cleanup, use `export-v2 list --location <parent path>` to list snapshots and `export-v2 delete --snapshot <URI>` to delete one (it asks for confirmation by default; add `--no-confirm` in automation scripts).

### Clusters and Cross-Machine Migration: Use Object Storage

A local `file://` snapshot that contains data **works only in standalone mode**, for two reasons. First, distributed clusters reject `COPY` access to the server's local disk (`--schema-only` exports only the schema and does not use `COPY`, so it is not affected). Second, a local path requires the CLI, the source, and the target to mount the same shared file system; if each container mounts its own local directory, they are not looking at the same files at all.

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/local-vs-object.png" alt="A file:// snapshot needs the CLI, source, and target to share one file system; with object storage they all access the same bucket" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

For distributed deployments or cross-machine migrations, the standard approach is to put the snapshot in object storage such as S3 or MinIO, so the CLI and both clusters access the same bucket. A MinIO example:

```bash
greptime cli data export-v2 create \
  --addr source.example.com:4000 \
  --to s3://my-bucket/snapshots/demo \
  --schemas public \
  --s3 --s3-region us-west-2 \
  --s3-endpoint http://minio.example.com:9000 \
  --s3-access-key-id "${S3_ACCESS_KEY_ID}" \
  --s3-secret-access-key "${S3_SECRET_ACCESS_KEY}"
```

The bucket name and path prefix come entirely from the `s3://...` URI (an extra `--s3-bucket` is ignored, and the CLI does not report a mismatch). Pass the same connection parameters to the later `verify`, `import-v2`, `list`, and `delete` commands, and make sure the CLI and both servers can reach the endpoint (with AWS S3, you can usually omit `--s3-endpoint`).

---

## Removing the Bottleneck of 100K Small Logical Tables

In observability workloads, GreptimeDB's Metric Engine lets thousands of logical tables share an underlying physical table. The physical table is a wide table holding the union of all logical tables' columns; each logical table (say, one for CPU metrics and another for HTTP request counts) maps only the few columns it needs:

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/logical-projection.png" alt="A Metric Engine physical table holds the union of columns; each logical table maps only the columns it needs" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

On the traditional per-table path, export fetches metadata, builds a query plan, and creates a small file for every table; restore reads metadata, runs CREATE TABLE, and writes data for every table one at a time. Even if each operation takes only a few milliseconds, multiply it by 100,000 and the fixed overhead becomes prohibitive.

To address this, we optimized three stages of the Metric Engine path:

### 1. Export: Shared Scan per Physical Table
Instead of issuing one query per logical table, the exporter runs a single shared scan over the underlying physical table. The stream is split in memory by `__table_id`, each logical table's columns are extracted and encoded directly to Parquet, and column types, order, and null semantics stay exactly the same.

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/shared-scan.png" alt="One shared scan over the physical table, split in memory by __table_id and encoded to Parquet per logical table" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

### 2. Storage: Packing Small Tables (Packed Layout)
A shared scan alone is not enough. If 100,000 small tables still land as 100,000 files of a few KB each, object storage still gets flooded with PUT requests.

In the `packed` layout, each small table is still encoded as a standard Parquet byte segment with its own schema and footer, but these segments are appended one after another into a single `pack` object, and an external index records each table's object name, `offset`, and `length`. Logical tables with different schemas can therefore share one file, and restore cuts out each table's segment by following the index. A pack file as a whole is not a valid Parquet file, so external tools cannot open it as regular Parquet.

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/packed-layout.png" alt="Each small table is a complete Parquet segment appended into one pack object, located by an index of object, offset, and length" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

### 3. Restore: Merged Range Reads with a Cache Window
If restore still sent one HTTP range request per small table, the network round-trip latency would remain. So the restore side uses a bounded range-read cache window: the adjacent bytes fetched along with table A (including the data of tables B and C) stay in the cache for later readers to reuse. Because the index already records byte lengths, the usual footer-probing requests when reading Parquet are also avoided.

<figure style="text-align: center">
  <img src="/blogs/2026-12-02-greptimedb-export-import-v2/range-read.png" alt="Neighboring small tables in a pack object reuse a bounded read window instead of issuing one range request each" style="max-width: 820px; width: 100%; display: block; margin: 0 auto">
</figure>

**Large-table routing and memory limits:**
Tables are routed by the size of their fully encoded Parquet in the current chunk: tables **up to 8 MiB** count as small and are packed; larger ones fall back to streaming into separate files. Single writes and multipart parts are also capped at 8 MiB (a pack object itself can be larger than 8 MiB). Keep in mind that 8 MiB is only the packing buffer threshold; when sizing node memory, also account for query, encoding, and concurrent-task overhead.

### Enabling the Optimizations in v1.3.2

In v1.3.2, this feature is experimental and must be **enabled on both the server and the CLI**.

First, add the following to the configuration of the standalone instance or of every frontend node in the cluster:

```toml
experimental_metric_export = true
```

Then pass the two experimental flags when exporting:

```bash
greptime cli data export-v2 create \
  --addr 127.0.0.1:4000 \
  --to file:///tmp/greptime-snapshots/metrics-packed \
  --schemas public \
  --experimental-metric-export \
  --metric-data-layout packed
```
* `--experimental-metric-export`: enables the shared scan per physical table (Parquet only). On startup, the CLI checks whether the server has the option enabled; if not, it exits with an error without touching the snapshot directory.
* `--metric-data-layout packed`: enables small-table packing (must be used together with the previous flag).

Restore needs no extra flags. Run the regular `import-v2`, and the importer detects the `packed` layout from the snapshot manifest. These flags only affect Metric Engine tables; regular tables in the same schema are not packed and are still exported as separate Parquet files (in the packed layout these files are named by table ID, such as `table-1024.parquet`, not by table name).

> **Coming next**: Two more usability and performance improvements are on the main branch but not yet in v1.3.x:
> 1. **Batched CREATE TABLE DDL**: create the physical table first, then submit compatible logical-table DDL in batches (`import-v2` in v1.3.2 still runs DDL one statement at a time).
> 2. **Simpler configuration**: the two export flags are merged into a single `--pack-metric-data`, and the server no longer needs a manual switch.

---

## Benchmark: Up to 180x Faster Migration on 100K Logical Tables

To see how this behaves in an extreme case, we built a dense logical-table test:
* **Data scale**: 10 physical tables with 10,000 logical tables each (**100,000 logical tables** in total). Each physical table has 300 columns; each logical table has 10 overlapping string tag columns, 1 timestamp column, and 1 DOUBLE metric column (12 columns). Each table has 32 rows, 3.2 million rows in total.
* **Network**: a proxy in front of MinIO injects a fixed **100 ms** delay into **every** object storage HTTP request (including range reads and multipart requests), simulating a real cross-datacenter or public cloud object storage setup.

The test used a main-branch build from October 12, 2026 (macOS release binary) and compared the traditional per-table path with the fully optimized path (shared scan + packed layout + batched table creation) under the same hardware resource limits:

| Metric | Per-table baseline | Fully optimized | Improvement |
| :--- | :--- | :--- | :--- |
| **Export time** | 3416.710 s (about 57 min) | **38.164 s** | **~89.5x** |
| **Restore time** | 6745.171 s (about 112 min) | **37.474 s** | **~180x** |
| **Export S3 requests** | 100,115 | **77** | 99.92% fewer |
| **Restore S3 requests** | 600,204 | **63** | 99.99% fewer |

*After each run, we verified all 100,000 tables end to end, checking data values, DDL, logical table ownership, and new table ID mappings, with a 100% pass rate.*

The fully optimized group includes the batched table creation from the main branch mentioned above (it reduced 100,000 logical-table creation procedures to 790, about 127 tables per batch; this optimization is not yet in v1.3.2). The final speedups of nearly 90x for export and 180x for restore come from all three optimizations combined. Real-world gains depend on table count, table size, column width, and object storage latency. See the [GitHub tracking issue (#9120)](https://github.com/GreptimeTeam/greptimedb/issues/9120) for full test details.

---

## Tuning Guide: How to Choose Time Windows and Parallelism

### Time window (chunk time window) tradeoffs
Smaller windows make each failed retry cheaper and create more tasks to run in parallel, but every chunk has to go through table list resolution, data scanning, and file writing again.
* **A few large tables over a very long time span**: smaller windows work well, giving you more concurrency and finer-grained resume.
* **Tens of thousands or 100,000 small tables**: windows that are too fine multiply the metadata traversal and scheduling overhead; use wider windows.

### Parallelism parameters
v2 provides concurrency controls at three levels:

| Parameter | Scope | Tuning advice |
| :--- | :--- | :--- |
| `--chunk-parallelism` | Number of time chunks exported at the same time (schemas within a chunk still run sequentially) | Default `1`; try `2` first (with only 1 chunk in total, raising it has no effect) |
| `--parallelism` | Execution parallelism inside a single server-side `COPY` | Default `1`; tune it separately from `--chunk-parallelism` |
| `--task-parallelism` | Number of `schema/chunk` data tasks imported at the same time | Default `1`; raise it gradually based on target write load and spare memory |

**Practical advice**: establish a baseline with the defaults, then **change only one concurrency parameter at a time**, and watch which runs out first: source query CPU, target write load, network bandwidth, or memory. If you raise both export parameters (`--chunk-parallelism` and `--parallelism`) at once, the load multiplies, and an OOM or timeout becomes hard to trace to its bottleneck.

### Other filtering and output options
* **Scope**: use `--schemas` to migrate only some schemas, and `--schema-only` to migrate only the schema. Time filtering can only be set during `export-v2`; `import-v2` takes all data in the snapshot, cannot trim it by time again, and currently cannot filter by individual table.
* **Progress display**: control progress output for long jobs with `--progress auto|always|never`. This option only applies to `create` and `import-v2`; passing it to `verify`, `list`, or `delete` fails with an unknown-argument error.

---

## Limits and Version Compatibility

Before using v2 for a production migration, keep these limits in mind:

1. **Source data should be static or stable**: During export, different tables and chunks are scanned at different times. If source tables are under heavy writes or schema changes, time-range filtering alone **cannot produce a consistent snapshot across tables**. v2 is therefore best for migrating archived historical data, or for running during a write-freeze maintenance window. Also, a time-based export is a range slice, not a WAL-based incremental backup; for real-time dual writes or continuous sync, use a dedicated data synchronization pipeline.
2. **Snapshot formats are separate from the old tool**:
    * The default per-table layout of `export-v2` uses `manifest v1`; the `packed` layout uses `manifest v2` (a `--schema-only` export still uses `v1`). `import-v2` handles both formats automatically.
    * Directories produced by the old `cli data export` have a completely different structure and still need the old `import` command to restore.
3. **Layout switching and `--force` risk**: Rerunning with unchanged parameters resumes in the original layout. Rerunning against an existing per-table snapshot path with the `packed` flags is rejected with an error. To switch to the `packed` layout, export to a new snapshot path, or add `--force` to wipe and recreate the snapshot. With `--force`, **the CLI deletes every file under that snapshot directory or S3 prefix**, so never keep any other files under that path!

---

## References

* [Export and Import Data with Export/Import V2](https://docs.greptime.com/user-guide/deployments-administration/disaster-recovery/export-import-v2/): the official user guide, covering how to create, verify, list, delete, and import snapshots.
* [Export / Import v2 RFC](https://github.com/GreptimeTeam/greptimedb/blob/main/docs/rfcs/2025-12-30-export-import-v2.md): the overall design of the snapshot structure, task scheduling, and resume.
* [Metric Export/Import Optimization RFC](https://github.com/GreptimeTeam/greptimedb/blob/main/docs/rfcs/2026-09-11-metric-export-import.md): design details of the shared physical-table scan, the packed storage format, and merged range reads.
* [Metric Export/Import Tracking Issue (#9120)](https://github.com/GreptimeTeam/greptimedb/issues/9120): the full development history, benchmark environment, and validation results.
