Skip to content
/ cnc Public

Seamless Database Replication tool

License

GPL-3.0, MIT licenses found

Licenses found

GPL-3.0
LICENSE-GPL-3.0
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

terra-sync/cnc

Repository files navigation

CNC-RS

CNC-RS is a Rust-based application for PostgreSQL database replication, configurable through a TOML file and a command-line interface (CLI). It features a robust logging system and optional email notifications to streamline database operations and ensure reliability.

Features

  • PostgreSQL Replication: Efficiently replicates data between PostgreSQL instances using pg_dump and psql.
  • Logging: Provides detailed logs, including timestamps and log levels, with output redirected to both the console and a log file (output.log).
  • Email Notifications: Configurable email notifications for replication success or failure using SMTP settings.
  • Flexible Backup Options: Supports full and schema-only backups.
  • CLI and Configuration File: Combines CLI options with a TOML configuration file for flexible operation and overrides.

Installation

Using cargo install

Install it using Cargo:

cargo install cnc-rs

From Source

  1. Clone the repository:

    git clone https://github.com/terra-sync/cnc
    cd cnc-rs
  2. Install globally using Cargo:

    cargo install --path .

Usage

Command-Line Options

cnc <path-to-config.toml> [--verbose] [--email <true|false>]
  • --verbose: Enables detailed logging to the console and output.log.
  • --email: Overrides the email notification setting in the configuration file.

Example

cnc ./config.toml --verbose --email true

Configuration

CNC-RS requires a configuration file in TOML format. Below is an example:

[postgres]
enabled = true
origin_host = "localhost"
origin_user = "postgres"
origin_password = "password"
origin_port = "5432"
origin_database = "source_db"
target_host = "localhost"
target_user = "postgres"
target_password = "password"
target_port = "5432"
target_database = "target_db"
backup_type = "Full" # Options: "Full" or "Schema"

[smtp]
enabled = true
username = "your_email_username"
password = "your_email_password"
smtp_host = "smtp.example.com"
smtp_port = 587
from = "[email protected]"
to = ["[email protected]", "[email protected]"]
cc = ["[email protected]"]

Sections

  • [postgres]:

    • enabled: Enables or disables PostgreSQL replication.
    • origin_*: Details for the source database.
    • target_*: Details for the target database.
    • backup_type: Type of backup (Full or Schema).
  • [smtp]:

    • enabled: Enables or disables email notifications.
    • username, password: SMTP credentials.
    • smtp_host, smtp_port: SMTP server details.
    • from: Email sender.
    • to: List of recipient emails.
    • cc: List of CC recipient emails (optional).

Logging

Logs are generated in both the console and a file named output.log. Each log entry includes:

  • A timestamp
  • Log level (e.g., INFO, WARN, ERROR)
  • Log message

Enable detailed logs using the --verbose flag.


Development

To contribute or modify this project:

  1. Clone the repository:

    git clone https://github.com/terra-sync/cnc
  2. Build the project:

    cargo build
  3. Run tests:

    cargo test

Example Workflow

  1. Create a configuration file (e.g., config.toml) based on the example above.
  2. Run the application with verbose logging and email notifications:
    cnc ./config.toml --verbose --email true
  3. Review the logs in output.log for replication details.
  4. Check your email for notifications if SMTP is enabled.

License

This project is licensed under the terms of both the MIT license and the GPL-3.0. See the LICENSE-MIT and LICENSE-GPL-3.0 files for details.


Acknowledgments

  • env_logger: For logging configuration.
  • lettre: For SMTP email support.
  • postgres: For interacting with PostgreSQL databases.
  • clap: For building the CLI.
  • serde: For configuration deserialization.

Contributing

Mailing Lists

For bugs, patches, or help, please reach out through our groups.io: