A CLI tool to export and import schema definitions and data from CockroachDB in SQL, JSON, YAML, or chunked CSV formats.
Project description
crdb-dump
A feature-rich CLI for exporting and importing CockroachDB schemas and data. Includes support for parallel chunked exports, manifest checksums, BYTES/UUID/ARRAY types, permission introspection, and secure resumable imports.
๐ Features
- โ Schema export: tables, views, sequences, enums
- โ Data export: CSV or SQL with chunking, gzip, and ordering
- โ Types: handles BYTES, UUIDs, STRING[], TIMESTAMP, enums
- โ
Schema output formats:
sql,json,yaml - โ
Resumable
COPY-based imports with chunk-level tracking - โ Permission exports: roles, grants, role memberships
- โ
Parallel loading (
--parallel-load) and manifest verification - โ Dry-run for schema or chunk loading
- โ TLS and insecure auth supported
- โ
Schema diff support (
--diff) - โ
Full logging via
logs/crdb_dump.log - โ Automatic retry logic for transient connection errors (e.g., server restarts)
- โ
Fault-tolerant, resumable imports using
--resume-logwith chunk-level tracking
๐ฆ Installation
pip install crdb-dump
๐งช Local Testing
./test-local.sh
This script will:
- Create test schema + data
- Export schema and data (CSV)
- Verify checksums
- Dry-run re-import
- Perform real import with
--validate-csvand--parallel-load
๐ง CLI Overview
crdb-dump --help
crdb-dump export --help
crdb-dump load --help
crdb-dump export --db=mydb --data --per-table
crdb-dump load --db=mydb --schema=... --data-dir=... --resume-log=resume.json
๐ Connection
export CRDB_URL="cockroachdb://root@localhost:26257/defaultdb?sslmode=disable"
# or
export CRDB_URL="postgresql://root@localhost:26257/defaultdb?sslmode=disable"
Alternatively, specify connection parts via flags:
--db mydb --host localhost --certs-dir ~/certs
Use --print-connection to verify resolved URL.
๐ Export Options
crdb-dump export \
--db=mydb \
--per-table \
--data \
--data-format=csv \
--chunk-size=1000 \
--data-order=id \
--data-compress \
--data-parallel \
--verify \
--include-permissions \
--archive
Schema Output
| Option | Description |
|---|---|
--per-table |
One file per object (e.g., table_users.sql) |
--format |
Output format: sql, json, yaml |
--diff |
Show schema diff vs previous .sql file |
--tables |
Comma-separated FQ names to include |
--exclude-tables |
Skip specific FQ table names |
--include-permissions |
Export roles, grants, and memberships |
Data Export
| Option | Description |
|---|---|
--data |
Enable data export |
--data-format |
Format: csv or sql |
--chunk-size |
Number of rows per chunk |
--data-split |
Output one file per table |
--data-compress |
Output .csv.gz |
--data-order |
Order rows by column(s) |
--data-order-desc |
Use descending order |
--data-parallel |
Parallel export across tables |
--verify |
Verify chunk checksums |
--archive |
Compress output into .tar.gz |
โ Import Options
crdb-dump load \
--db=mydb \
--schema=crdb_dump_output/mydb/mydb_schema.sql \
--data-dir=crdb_dump_output/mydb \
--resume-log=resume.json \
--validate-csv \
--parallel-load \
--print-connection
| Option | Description |
|---|---|
--schema |
.sql file to apply |
--data-dir |
Folder containing chunked CSV and manifests |
--resume-log |
JSON file to resume partial loads |
--validate-csv |
Fail early if column mismatch is detected |
--parallel-load |
Load chunks using multiple threads |
--dry-run |
Print what would be loaded, but skip action |
--include-tables |
Restrict to specific FQ table names |
--exclude-tables |
Skip specific FQ table names |
--print-connection |
Echo resolved DB connection |
๐ Output Structure
crdb_dump_output/mydb/
โโโ mydb_schema.sql
โโโ mydb_schema.json
โโโ mydb_schema.yaml
โโโ mydb_schema.diff
โโโ table_users.sql
โโโ users_chunk_001.csv
โโโ users.manifest.json
โโโ roles.sql
โโโ grants.sql
โโโ role_memberships.sql
โโโ permissions.sql
๐ Schema Diff Example
crdb-dump export --db=mydb --diff=old_schema.sql
Result written to:
crdb_dump_output/mydb/mydb_schema.diff
๐งช Testing
pytest -m unit
pytest -m integration
./test-local.sh
๐งโ๐ป Developer Notes
- Based on
click+sqlalchemy+psycopg2 - PEP 621 pyproject-based project layout
- Supports TLS via
--certs-diror insecure fallback - Uses CockroachDB
SHOW CREATE,COPY, andGRANTS - Tested with CockroachDB v25.2
- CI runs via GitHub Actions + Docker
โค๏ธ Contributing
Pull requests welcome! Star โญ the repo, file issues, or request features at:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crdb_dump-0.2.6.tar.gz.
File metadata
- Download URL: crdb_dump-0.2.6.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca975fa9066757959e46bada897e8d5b479804363b767f3bee4f9c9f130ec707
|
|
| MD5 |
85a219dbb2427519c4fd62037d2ff278
|
|
| BLAKE2b-256 |
150d899b1fc671c6c1a5d3dd8e688107e6d702a22409b3eed545bdf85d6bbe70
|
File details
Details for the file crdb_dump-0.2.6-py3-none-any.whl.
File metadata
- Download URL: crdb_dump-0.2.6-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6726e6c79ef3bed7929fe0666ecb8da3c0d11c83943e971f4c114a08beb2684e
|
|
| MD5 |
7469b3aa18166422de16159a5ad95181
|
|
| BLAKE2b-256 |
d6a488a1aad8f125aa2623d677d0087c27f31f0adc4adc4a763440e46b7a87a6
|