2 releases
new 0.1.4 | Dec 23, 2024 |
---|---|
0.1.3 | Dec 22, 2024 |
0.1.2 |
|
0.1.1 |
|
0.1.0 |
|
#348 in Database interfaces
171 downloads per month
33KB
434 lines
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
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.
Installation
Using cargo install
Install it using Cargo:
cargo install cnc-rs
From Source
-
Clone the repository:
git clone https://github.com/terra-sync/cnc cd cnc-rs
-
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 andoutput.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 = "your_email@example.com"
to = ["recipient1@example.com", "recipient2@example.com"]
cc = ["cc_recipient@example.com"]
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
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).
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:
-
Clone the repository:
git clone https://github.com/terra-sync/cnc
-
Build the project:
cargo build
-
Run tests:
cargo test
Example Workflow
- 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.
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:
- Post: cnc@groups.io
- Subscribe: cnc+subscribe@groups.io
- Unsubscribe: cnc+unsubscribe@groups.io
- Group Owner: cnc+owner@groups.io
- Help: cnc+help@groups.io
Dependencies
~14–44MB
~710K SLoC