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.
- PostgreSQL Replication: Efficiently replicates data between PostgreSQL instances using
pg_dump
andpsql
. - 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.
Install it using Cargo:
cargo install cnc-rs
-
Clone the repository:
git clone https://github.com/terra-sync/cnc cd cnc-rs
-
Install globally using Cargo:
cargo install --path .
cnc <path-to-config.toml> [--verbose] [--email <true|false>]
--verbose
: Enables detailed logging to the console andoutput.log
.--email
: Overrides the email notification setting in the configuration file.
cnc ./config.toml --verbose --email true
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]"]
-
[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
orSchema
).
-
[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).
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.
To contribute or modify this project:
-
Clone the repository:
git clone https://github.com/terra-sync/cnc
-
Build the project:
cargo build
-
Run tests:
cargo test
- Create a configuration file (e.g.,
config.toml
) based on the example above. - Run the application with verbose logging and email notifications:
cnc ./config.toml --verbose --email true
- Review the logs in
output.log
for replication details. - Check your email for notifications if SMTP is enabled.
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.
- 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.
For bugs, patches, or help, please reach out through our groups.io:
- Post: [email protected]
- Subscribe: [email protected]
- Unsubscribe: [email protected]
- Group Owner: [email protected]
- Help: [email protected]