Skip to main content

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

Project description

PyPI version Python versions License Build status

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-log with 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-csv and --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-dir or insecure fallback
  • Uses CockroachDB SHOW CREATE, COPY, and GRANTS
  • Tested with CockroachDB v25.2
  • CI runs via GitHub Actions + Docker

โค๏ธ Contributing

Pull requests welcome! Star โญ the repo, file issues, or request features at:

๐Ÿ‘‰ https://github.com/viragtripathi/crdb-dump/issues

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.2.6.tar.gz (19.9 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.2.6-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

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

Hashes for crdb_dump-0.2.6.tar.gz
Algorithm Hash digest
SHA256 ca975fa9066757959e46bada897e8d5b479804363b767f3bee4f9c9f130ec707
MD5 85a219dbb2427519c4fd62037d2ff278
BLAKE2b-256 150d899b1fc671c6c1a5d3dd8e688107e6d702a22409b3eed545bdf85d6bbe70

See more details on using hashes here.

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

Hashes for crdb_dump-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6726e6c79ef3bed7929fe0666ecb8da3c0d11c83943e971f4c114a08beb2684e
MD5 7469b3aa18166422de16159a5ad95181
BLAKE2b-256 d6a488a1aad8f125aa2623d677d0087c27f31f0adc4adc4a763440e46b7a87a6

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