A command-line utility for managing database backups with support for both local and cloud storage. Currently supports PostgreSQL databases, with extensible architecture for future database support.
-
Database Support
- PostgreSQL (current)
- Extensible architecture for future database types (MySQL, MongoDB, etc.)
-
Storage Options
- Local filesystem storage
- Google Cloud Storage integration
- Compressed backup support
-
Notifications
- Slack integration for backup/restore notifications
- Detailed logging system
-
Operations
- Backup creation (local/cloud)
- Backup restoration
- Backup deletion
- Backup listing
- Scheduled backups
- Google Cloud account (with billing)
- Database account and connection credentials
brew install postgresql@15- Clone the repository:
git clone <repository-url>
cd backup-utility- Create a virtual environment:
python -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
touch .env.localEdit .env.local with your database credentials:
SUPABASE_NAME=your_database
SUPABASE_USER=your_username
SUPABASE_HOST=your_host
SUPABASE_PASSWORD=your_password
SUPABASE_PORT=database_port
- Configure the application:
touch config.jsonEdit config.json with your settings:
{
"local_storage_dir": "/path/to/backup/directory",
"use_cloud": true,
"compress": true,
"db_type": "postgres",
"store_locally": true,
"store_in_cloud": true,
"notification_enabled": true,
"slack_webhook": "your_slack_webhook_url",
"cloud_storage": {
"type": "gcs",
"bucket": "your_bucket_name",
"region": "your_region",
"project_id": "your_project_id"
}
}python main.py backup --db postgrespython main.py backup --db postgres --cloudpython main.py backup --db postgres --compresspython main.py restore --listpython main.py restore --list --cloudpython main.py restore --file backup_filename.dumppython main.py restore --file backup_filename.dump --cloudpython main.py restore --file backup_filename.dump --target-db new_database_namepython main.py delete --file backup_filename.dumppython main.py delete --file backup_filename.dump --cloud- Make the scheduler executable:
chmod +x scheduler.py- Add to crontab (example for daily backup at 2 AM):
crontab -eAdd the line:
0 2 * * * cd /path/to/backup-utility && /path/to/venv/bin/python scheduler.py
Logs are stored in the logs/backup.log file. The logging system uses rotation to maintain file sizes, keeping the last 5 log files with a maximum size of 10MB each.
- Install Google Cloud SDK
- Authenticate with Google Cloud:
gcloud auth application-default login- Set your project:
gcloud config set project your-project-id- Ensure your service account has the necessary permissions for Google Cloud Storage operations.