Skip to content

BackupForge is a powerful and flexible command‑line database backup utility designed to simplify the process of backing up, restoring, and managing database backups across multiple database types. It provides an easy‑to‑use CLI interface with support for local and cloud storage, compression, scheduling, and notifications.

Notifications You must be signed in to change notification settings

RajeshBasnet-dev/Database_Backup_Utility_CLI

Repository files navigation

BackupForge

Build Status Version License Python Version

BackupForge is a command-line database backup utility that provides a simple and efficient way to backup and restore databases. It supports multiple database types and storage options, with features like compression and scheduling.

This project is available on GitHub at: https://github.com/RajeshBasnet-dev/Database_Backup_Utility_CLI

Features

  • 🔥 Multiple Database Support: MySQL, PostgreSQL, MongoDB, and SQLite
  • 💾 Storage Options: Local storage and AWS S3
  • 🗜️ Compression: ZIP and GZIP compression for backup files
  • Scheduling: Automated backup scheduling
  • 📢 Notifications: Slack webhook integration for backup notifications
  • 🌐 Cross-platform: Works on Windows, Linux, and macOS

Quick Start Guide

Installation

  1. Clone the repository:
    git clone https://github.com/RajeshBasnet-dev/Database_Backup_Utility_CLI.git
    cd Database_Backup_Utility_CLI
  2. Install the required dependencies:
    pip install -r requirements.txt
  3. Make sure you have the database clients installed:
    • MySQL: mysqldump and mysql
    • PostgreSQL: pg_dump and pg_restore
    • MongoDB: mongodump and mongorestore

Basic Usage

Backup MySQL Database:

backupforge backup --db-type mysql --host localhost --username root --password root --database testdb

Restore PostgreSQL Database:

backupforge restore --db-type postgres --host localhost --username postgres --password postgres --database testdb --file backup.sql

Database Support Comparison

Database Backup Restore Compression Cloud Storage Notifications
MySQL
PostgreSQL
MongoDB
SQLite

Architecture Diagram

graph LR
    A[CLI Interface] --> B[Command Parser]
    B --> C{Database Type}
    C --> D[MySQL Connector]
    C --> E[PostgreSQL Connector]
    C --> F[MongoDB Connector]
    C --> G[SQLite Connector]
    D --> H[Backup/Restore Logic]
    E --> H
    F --> H
    G --> H
    H --> I{Storage Type}
    I --> J[Local Storage]
    I --> K[Cloud Storage]
    H --> L[Compression]
    H --> M[Logging]
    H --> N[Notifications]
Loading

Installation

  1. Clone the repository:
    git clone https://github.com/RajeshBasnet-dev/Database_Backup_Utility_CLI.git
    cd Database_Backup_Utility_CLI
  2. Install the required dependencies:
    pip install -r requirements.txt
  3. Make sure you have the database clients installed:
    • MySQL: mysqldump and mysql
    • PostgreSQL: pg_dump and pg_restore
    • MongoDB: mongodump and mongorestore

Usage

Backup

Create a backup of your database:

backupforge backup --db-type mysql --host localhost --port 3306 --username user --password pass --database mydb

With compression and S3 storage:

backupforge backup --db-type postgres --host localhost --username user --password pass --database mydb --compress zip --storage s3 --bucket my-backup-bucket --region us-east-1 --access-key YOUR_ACCESS_KEY --secret-key YOUR_SECRET_KEY

Restore

Restore a database from a backup:

backupforge restore --db-type mysql --host localhost --port 3306 --username user --password pass --database mydb --file backup.sql

Test Connection

Test database connection parameters:

backupforge test-connection --db-type mongodb --host localhost --port 27017 --username user --password pass --database mydb

Schedule Backups

Schedule automated backups:

backupforge schedule --db-type sqlite --database /path/to/database.db --interval 60

List Backups

List existing backups:

backupforge list --storage local --path /backups

Or from S3:

backupforge list --storage s3 --bucket my-backup-bucket --region us-east-1 --access-key YOUR_ACCESS_KEY --secret-key YOUR_SECRET_KEY

Configuration

Environment Variables

For Slack notifications, set the SLACK_WEBHOOK_URL environment variable:

export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"

AWS Credentials

For S3 storage, you can provide credentials via:

  1. Command line arguments (--access-key, --secret-key)
  2. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  3. AWS credentials file

Examples

MySQL Backup Examples

# Simple backup
backupforge backup --db-type mysql --host localhost --username root --password root --database testdb

# Backup with compression to S3
backupforge backup --db-type mysql --host localhost --username root --password root --database testdb --compress gzip --storage s3 --bucket my-backups --region us-west-2 --access-key AKIA... --secret-key ...

# Backup to specific local path
backupforge backup --db-type mysql --host localhost --username root --password root --database testdb --path /my/backups

PostgreSQL Backup Examples

# Simple backup
backupforge backup --db-type postgres --host localhost --username postgres --password postgres --database testdb

# Restore from backup
backupforge restore --db-type postgres --host localhost --username postgres --password postgres --database testdb --file backup.sql

MongoDB Backup Examples

# Backup MongoDB
backupforge backup --db-type mongodb --host localhost --port 27017 --username admin --password admin --database testdb

# Backup with compression
backupforge backup --db-type mongodb --host localhost --username admin --password admin --database testdb --compress zip

SQLite Backup Examples

# Backup SQLite database
backupforge backup --db-type sqlite --database /path/to/mydb.sqlite

# Restore SQLite database
backupforge restore --db-type sqlite --database /path/to/mydb.sqlite --file backup.db

Scheduling Backups

The schedule command runs indefinitely, performing backups at the specified interval (in minutes):

# Schedule backups every 30 minutes
backupforge schedule --db-type mysql --host localhost --username user --password pass --database mydb --interval 30

# Schedule with compression and S3 storage
backupforge schedule --db-type postgres --host localhost --username user --password pass --database mydb --interval 120 --compress zip --storage s3 --bucket my-backups --region us-east-1 --access-key ... --secret-key ...

Press Ctrl+C to stop the scheduler.

Storage Options

Local Storage

  • Specify with --storage local
  • Use --path to define the backup directory (defaults to ./backups)

S3 Storage

  • Specify with --storage s3
  • Required parameters: --bucket, --region, --access-key, --secret-key

Compression Options

  • --compress zip: Compress using ZIP format
  • --compress gzip: Compress using GZIP format

CLI Command Alias

BackupForge supports a shorter alias for easier usage:

Full command:

backupforge backup --db-type mysql --host localhost --username user --password pass --database mydb

Shorter alias:

bforge backup --db-type mysql --host localhost --username user --password pass --database mydb

Supported Database Parameters

MySQL/PostgreSQL

  • --host: Database host (default: localhost)
  • --port: Database port (default: 3306 for MySQL, 5432 for PostgreSQL)
  • --username: Database username
  • --password: Database password
  • --database: Database name

MongoDB

  • --host: Database host (default: localhost)
  • --port: Database port (default: 27017)
  • --username: Database username
  • --password: Database password
  • --database: Database name

SQLite

  • --database: Path to SQLite database file

Error Handling

BackupForge includes comprehensive error handling:

  • Connection testing before operations
  • Proper cleanup of partial backups on failure
  • Detailed error messages
  • Logging to backupforge.log

Logging

All operations are logged to logs/backupforge.log in the current directory.

Contributing Guidelines

We welcome contributions from the community! Here's how you can help improve BackupForge:

Ways to Contribute

  • 🐛 Bug Reports: Submit detailed bug reports with reproduction steps
  • Feature Requests: Suggest new features or improvements
  • 🧪 Testing: Test new releases and report issues
  • 📝 Documentation: Improve documentation and examples
  • 🐍 Code: Fix bugs, add features, or improve code quality

Getting Started

  1. Fork the repository at https://github.com/RajeshBasnet-dev/Database_Backup_Utility_CLI
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests if applicable
  5. Ensure all tests pass
  6. Commit your changes (git commit -m 'Add some amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Setup

git clone https://github.com/RajeshBasnet-dev/Database_Backup_Utility_CLI.git
cd Database_Backup_Utility_CLI
pip install -r requirements.txt

Code Standards

  • Follow PEP 8 style guidelines
  • Write clear, descriptive commit messages
  • Add docstrings to all functions and classes
  • Include tests for new functionality

Questions?

If you have questions, feel free to open an issue or contact the maintainers.

License

This project is licensed under the MIT License.

About

BackupForge is a powerful and flexible command‑line database backup utility designed to simplify the process of backing up, restoring, and managing database backups across multiple database types. It provides an easy‑to‑use CLI interface with support for local and cloud storage, compression, scheduling, and notifications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages