The Database Guardian is a command-line interface (CLI) utility built in Go for backing up and restoring databases. It supports multiple database management systems (DBMS) such as MySQL, PostgreSQL, MongoDB, and SQLite. This tool allows users to schedule automatic backups, compress backup files, and store them locally or in the cloud. Additionally, it features logging and optional Slack notifications for backup activities.
- Supported DBMS: MySQL, PostgreSQL, MongoDB, SQLite
- Connection Parameters: Specify host, port, username, password, and database name.
- Connection Testing: Validate database credentials before performing backup operations.
- Backup Types:
- Full Backup
- Incremental Backup
- Differential Backup
- Compression: Compress backup files to save storage space.
- Local Storage: Save backup files locally on your system.
- Cloud Storage:
- AWS S3
- Google Cloud Storage
- Azure Blob Storage
- Logging: Track all backup activities, including start time, end time, status, and errors.
- Notifications: Send Slack notifications upon backup completion.
- Restore databases from backup files.
- Selectively restore specific tables or collections (if supported by the DBMS).
- Schedule backups using cron jobs.
- Go (1.18 or later)
- Database client tools (e.g.,
mysqldump
,pg_dump
,mongodump
for respective DBMS) - Cloud SDKs for cloud storage integrations
- Clone the repository:
git clone https://github.com/Annany2002/Data-Guardian.git
- Navigate to the project directory:
cd db_backup_tool
- Install dependencies:
go mod tidy
- Build the CLI:
go build -o db_backup_tool ./cmd/main.go
./db_backup_tool backup --db-type mysql --host localhost --port 3306 --user root --password secret --db-name mydb --type full --output /backups
--db-type
: Type of the database (mysql
,postgres
,mongodb
,sqlite
).--host
: Database host.--port
: Database port.--user
: Username for database access.--password
: Password for database access.--db-name
: Name of the database to back up.--type
: Backup type (full
,incremental
,differential
).--output
: Directory to save the backup file.
./db_backup_tool restore --db-type postgres --backup-file /backups/mydb_backup.gz
--db-type
: Type of the database.--backup-file
: Path to the backup file.--restore-tables
: (Optional) Comma-separated list of tables to restore.
Use the schedule
subcommand to automate backups:
./db_backup_tool schedule --interval "0 2 * * *" --command "./db_backup_tool backup ..."
To enable Slack notifications, set your Slack webhook URL in the environment variables:
export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url
You can configure default settings in config/config.yaml
:
mysql:
host: localhost
port: 3306
user: root
password: secret
db_name: mydb
storage:
local: /backups
cloud: aws
aws:
bucket: your-bucket-name
region: us-west-1
Logs are stored in logs/backup.log
by default. You can change the log path in the configuration file.
Run tests to ensure the tool works as expected:
cd tests
go test ./...
This project is licensed under the MIT License. See the LICENSE
file for details.
Contributions are welcome! Please submit a pull request or open an issue to report bugs or suggest improvements.
For any questions or feedback, feel free to contact [email protected]