Skip to main content

A modular CLI tool to dump CockroachDB schemas and data into SQL, JSON, YAML, or chunked CSV files.

Project description

PyPI version Python versions License Build status

crdb-dump

A CLI tool to export and import schema definitions and data from CockroachDB in SQL, JSON, YAML, or chunked CSV formats.

Supports chunking, parallelism, resumability, diffing, manifest checksums, BYTES and UUID types, TLS auth, and dry-run safety.


🚀 Features

  • Export tables, views, sequences, and user-defined types
  • Output formats: SQL, JSON, YAML, CSV (with optional gzip)
  • Export BYTES as decode('<hex>', 'hex')
  • Handles UUIDs, TIMESTAMPS, arrays
  • Create per-table schema files or a unified schema file
  • Parallel + chunked data export with manifest and row tracking
  • Resumable COPY-based data import
  • Schema + data dry-run mode
  • Schema diffing against previous .sql
  • CLI output + logging to logs/
  • TLS certs or insecure connection supported
  • --print-connection shows full resolved DB URL (safe)

🔧 Installation

pip install crdb-dump

🥺 Local Testing

Run an integration test:

./test-local.sh

This performs:

  • Schema + data export (with BYTES, UUID)
  • Chunked CSV manifest creation
  • Dry-run import
  • Full schema and data reload

🗋 Usage

crdb-dump export --db=mydb [options]
crdb-dump load --db=mydb --schema=<.sql> --data-dir=...

🔐 Connection Options

export CRDB_URL="cockroachdb://root@localhost:26257/defaultdb?sslmode=disable"

or use flags:

--db mydb --host localhost --certs-dir ~/certs

🏠 Export Options

crdb-dump export --db=mydb --data --data-format=csv --chunk-size=1000
Option Description
--data Enable data export
--data-format csv or sql output
--data-compress Output .csv.gz instead
--chunk-size Split into fixed-row chunks
--per-table Write per-table files
--data-order Order rows (e.g., by id)
--data-order-desc Order descending
--data-parallel Export tables in parallel
--verify Check manifest SHA256s
--print-connection Show resolved DB connection URL
--archive Create .tar.gz from exported folder

🛬 Load Options

crdb-dump load \
  --db=mydb \
  --schema=defaultdb_schema.sql \
  --data-dir=export/defaultdb \
  --resume-log=resume.json \
  --print-connection \
  --dry-run
Option Description
--schema Load schema from .sql file
--data-dir Path containing chunked CSVs and manifests
--resume-log Resume tracking file for chunked load
--dry-run Don't execute, just print plan
--include-tables Restrict to specific table names
--exclude-tables Skip specific table names
--print-connection Print resolved CockroachDB connection

📂 Output Structure

By default, output is stored under:

crdb_dump_output/<db_name>/
├── defaultdb_schema.sql
├── table_users.sql
├── users_chunk_001.csv
├── users.manifest.json
├── logins_chunk_001.csv
├── logins.manifest.json

All logs go to:

logs/crdb_dump.log

📄 Example: Full Export + Verify + Import

crdb-dump export \
  --db=defaultdb \
  --data \
  --data-format=csv \
  --chunk-size=1000 \
  --per-table \
  --verify \
  --archive \
  --print-connection

crdb-dump load \
  --db=defaultdb \
  --schema=crdb_dump_output/defaultdb/defaultdb_schema.sql \
  --data-dir=crdb_dump_output/defaultdb \
  --resume-log=resume.json \
  --print-connection

🔍 Schema Diffing

crdb-dump export \
  --db=defaultdb \
  --diff=previous_schema.sql

This prints a unified diff and writes to:

crdb_dump_output/<db_name>/<db_name>_schema.diff

🤖 Test Coverage

  • pytest -m unit – runs fast unit tests
  • pytest -m integration – full Docker-based test
  • ./test-local.sh – end-to-end data roundtrip

🛠️ Developer Notes

  • Configured via pyproject.toml (PEP 621)
  • Click-based CLI
  • Tested with CRDB v25.2
  • CI runs all tests via GitHub Actions and Docker

👤 Author

Created by Virag Tripathi MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crdb_dump-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crdb_dump-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file crdb_dump-0.1.0.tar.gz.

File metadata

  • Download URL: crdb_dump-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for crdb_dump-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7b4f281b16fc7779f2960ad0eb98134e5ae5744ed25cef21dc620700579e4941
MD5 5d4d5aa52cecdd12db0d36054a835937
BLAKE2b-256 b34c2ce6c9f106058960bf3f733a8a729ca046b54c6eaea17fc15bef9aad7ee9

See more details on using hashes here.

File details

Details for the file crdb_dump-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: crdb_dump-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for crdb_dump-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b1ae4ad17c486c9047c4f80248bc64c4b1f31ea116e36290fd654dc3f3dcc80
MD5 d5b62edceb5eb2855e372c73302174b1
BLAKE2b-256 090b70f1d948e29b969575c7c926d9b95761d950e14d3ed2b8593ac831afc370

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page