A powerful command-line interface for managing PeerDB mirrors via gRPC. This CLI provides complete control over PeerDB mirror operations including creation, monitoring, editing, and deletion of mirrors and peer connections.
- Mirror Management: Create, list, pause, resume, drop, and edit CDC mirrors
- Peer Management: Create, list, validate, and drop peer connections
- Configuration Management: Easy configuration with YAML files and environment variables
- Multiple Database Support: PostgreSQL, BigQuery, Snowflake, and more
- Real-time Status: Monitor mirror status and progress
- Cross-platform: Available for Linux, macOS, and Windows
- Go 1.21 or later
- buf CLI tool for protobuf generation
- Access to a running PeerDB instance
# Clone and build
git clone <your-repo>
cd mirror_cli
make build
# Install to $GOPATH/bin
make install# Download the latest release for your platform
curl -L https://github.com/your-org/mirror_cli/releases/latest/download/mirror_cli-$(uname -s)-$(uname -m) -o mirror_cli
chmod +x mirror_cli
sudo mv mirror_cli /usr/local/bin/- Initialize configuration:
mirror_cli config init- Configure PeerDB connection:
mirror_cli config set --host localhost --port 8112- Test connection:
mirror_cli peer listMirror CLI supports managing peers and mirrors through YAML configuration files, enabling GitOps workflows and version control of your data replication infrastructure.
configs/
├── peers/
│ ├── production/
│ ├── staging/
│ └── development/
├── mirrors/
│ ├── production/
│ ├── staging/
│ └── development/
└── examples/
├── peer-examples/
└── mirror-examples/
PostgreSQL Peer Configuration:
apiVersion: v1
kind: Peer
metadata:
name: postgres_source
environment: production
description: Primary PostgreSQL database
spec:
type: postgres
config:
host: postgres.company.com
port: 5432
user: peerdb_user
password: ${POSTGRES_PASSWORD}
database: users_db
metadata_schema: _peerdb_internalSnowflake Peer Configuration:
apiVersion: v1
kind: Peer
metadata:
name: snowflake_warehouse
environment: production
description: Snowflake data warehouse
spec:
type: snowflake
config:
account_id: ${SNOWFLAKE_ACCOUNT}
username: peerdb_user
private_key: ${SNOWFLAKE_PRIVATE_KEY}
database: ANALYTICS_DB
warehouse: COMPUTE_WH
role: PEERDB_ROLECDC Mirror Configuration:
apiVersion: v1
kind: Mirror
metadata:
name: users_sync_mirror
environment: production
description: Sync user data from PostgreSQL to Snowflake
spec:
type: cdc
source: postgres_source
destination: snowflake_warehouse
tables:
- source: public.users
destination: ANALYTICS_DB.PUBLIC.USERS
partition_key: created_at
- source: public.user_profiles
destination: ANALYTICS_DB.PUBLIC.USER_PROFILES
exclude_columns:
- password_hash
- ssn
cdc:
batch_size: 1000
idle_timeout_seconds: 60
initial_snapshot: true
publication_name: peerdb_users_pub
replication_slot_name: peerdb_users_slot# Validate configuration files
mirror_cli config validate -f configs/peers/production/
mirror_cli config validate -f configs/mirrors/production/users-sync.yaml
# Apply configurations (with dry-run first)
mirror_cli config apply -f configs/peers/production/ --dry-run
mirror_cli config apply -f configs/peers/production/
# Apply single configuration
mirror_cli config apply -f configs/mirrors/production/users-sync.yaml
# Export existing configurations
mirror_cli config export-peer my_postgres --output configs/peers/production/postgres.yaml
mirror_cli config export-mirror my_mirror --output configs/mirrors/production/users-sync.yaml- Define Infrastructure: Create YAML configurations in
configs/ - Version Control: Commit configurations to git
- Validate: Run
config validatein CI/CD pipelines - Apply: Use
config applyto deploy changes - Monitor: Check status with
mirror status
Configuration files support environment variable substitution using ${VAR_NAME} syntax:
export POSTGRES_PASSWORD="secure_password"
export SNOWFLAKE_ACCOUNT="myaccount.us-east-1"
export SNOWFLAKE_PRIVATE_KEY="$(cat private_key.pem)"The CLI uses a YAML configuration file located at ~/.mirror_cli/config.yaml. You can also use environment variables or command-line flags.
- Command-line flags:
--host,--port,--tls - Environment variables:
MIRROR_CLI_PEERDB_HOST,MIRROR_CLI_PEERDB_PORT,MIRROR_CLI_TLS - Configuration file:
~/.mirror_cli/config.yaml
peerdb_host: "localhost"
peerdb_port: 8112
tls: false
username: ""
password: ""mirror_cli peer create \
--name my_postgres \
--type postgres \
--pg-host localhost \
--pg-port 5432 \
--pg-user postgres \
--pg-password mypassword \
--pg-database mydbmirror_cli peer create \
--name my_bigquery \
--type bigquery \
--bq-project my-project \
--bq-dataset my_dataset \
--bq-private-key "$(cat service-account.json | jq -r .private_key)" \
--bq-client-email service@my-project.iam.gserviceaccount.commirror_cli peer create \
--name my_snowflake \
--type snowflake \
--sf-account myaccount.us-east-1 \
--sf-user myuser \
--sf-password mypassword \
--sf-database MYDB \
--sf-warehouse COMPUTE_WH \
--sf-role ACCOUNTADMINmirror_cli peer listmirror_cli peer validate \
--name test_peer \
--type postgres \
--pg-host localhost \
--pg-user postgres \
--pg-database testdbmirror_cli peer drop my_postgres --forcemirror_cli mirror create \
--name my_cdc_mirror \
--source my_postgres \
--destination my_bigquery \
--tables "public.users->dataset.users,public.orders->dataset.orders" \
--batch-size 1000 \
--idle-timeout 60 \
--publication peerdb_pub \
--replication-slot peerdb_slotmirror_cli mirror listmirror_cli mirror status my_cdc_mirrormirror_cli mirror pause my_cdc_mirrormirror_cli mirror resume my_cdc_mirror# Add new tables
mirror_cli mirror edit my_cdc_mirror \
--add-tables "public.products->dataset.products" \
--batch-size 2000
# Remove tables
mirror_cli mirror edit my_cdc_mirror \
--remove-tables "public.old_table->dataset.old_table"mirror_cli mirror drop my_cdc_mirror --forcemirror_cli config showmirror_cli config set --host production.peerdb.com --port 8112 --tlsmirror_cli config init --force--config: Config file path (default:~/.mirror_cli/config.yaml)--host: PeerDB server host (default:localhost)--port: PeerDB server port (default:8112)--tls: Use TLS connection--username: Username for authentication--password: Password for authentication
| Command | Description |
|---|---|
mirror create |
Create a new CDC mirror |
mirror list |
List all mirrors |
mirror status |
Get detailed mirror status |
mirror pause |
Pause a running mirror |
mirror resume |
Resume a paused mirror |
mirror edit |
Edit mirror configuration |
mirror drop |
Drop a mirror permanently |
| Command | Description |
|---|---|
peer create |
Create a new peer connection |
peer list |
List all peer connections |
peer validate |
Validate peer configuration |
peer drop |
Drop a peer connection |
| Command | Description |
|---|---|
config show |
Show current CLI configuration |
config set |
Set CLI configuration values |
config init |
Initialize new CLI configuration |
config apply |
Apply peer/mirror configurations from files |
config validate |
Validate configuration files |
config export-peer |
Export peer configuration to file |
config export-mirror |
Export mirror configuration to file |
# Build for current platform
make build
# Build for all platforms
make build-all
# Generate protobuf files
make proto
# Install dependencies
make deps# Run tests
make test
# Run tests with coverage
make test-coverage
# Lint code
make lint- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests:
make test - Run linter:
make lint - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
-
Connection Failed
Error: failed to connect to PeerDB at localhost:8112- Verify PeerDB is running on the specified host and port
- Check if the gRPC port (8112) is accessible
- Ensure firewall rules allow the connection
-
Authentication Failed
- Verify username and password are correct
- Check if authentication is required for your PeerDB instance
-
Invalid Peer Configuration
- Use
peer validatecommand to check configuration before creating - Verify connection details (host, port, credentials)
- Check database permissions
- Use
-
Mirror Creation Failed
- Ensure source and destination peers exist and are valid
- Verify table names and mapping format
- Check if replication slot and publication exist (for PostgreSQL)
- Use
mirror_cli --helpfor general help - Use
mirror_cli [command] --helpfor command-specific help - Check the PeerDB documentation for more details
This project is licensed under the MIT License - see the LICENSE file for details.