Modular, secure database backup and restore system with MySQL support
Project description
BackyDB
A modular backup and restore system designed to provide flexible, secure, and efficient database backups with support for MySQL and extensible architecture.
Features
- Modular architecture with components for compression, encryption, integrity, storage, and more
- Supports MySQL database backup and restore with SQL export or compressed/encrypted formats
- Flexible configuration via YAML or JSON
- Integration with security tools including local and Google Cloud keystore, and AWS KMS support
- Supports multiple backup modes: raw SQL, compressed only, encrypted only, or full backup (compressed + encrypted)
- Multiple compression options: ZIP, TAR
- Hybrid encryption with AES-GCM and RSA-4096
- Metadata generation for backup integrity and management
- Validator module for HMAC and checksum verification
- Supports local storage and AWS S3
- Designed for extensibility with cloud provider support planned
Installation
You can install backy_db using pip:
pip install backy-db
To include optional dependencies, use:
-
For AWS support:
pip install backy-db[aws]
-
For Google Cloud Platform support:
pip install backy-db[gcp]
-
For full installation with all optional dependencies:
pip install backy-db[full]
Requirements
- Python 3.9 or higher
- MySQL server (if using MySQL backup features)
Usage
BackyDB supports flexible backup and restore workflows with customizable options for compression, encryption, integrity checks, storage, and backup feature selection.
Backup Features
- Backup format:
- If no compression and no encryption are enabled, the backup will be a plain SQL dump file (
.sql). - If compression, encryption, or both are enabled, the backup file will have a
.backyextension.
- If no compression and no encryption are enabled, the backup will be a plain SQL dump file (
- Metadata generation and optional integrity check are created after the backup.
- Backup modes:
- Raw SQL: Direct SQL dump without compression or encryption.
- Compressed only: Backup is compressed but not encrypted.
- Encrypted only: Backup is encrypted but not compressed.
- Full backup: Backup is both compressed and encrypted.
- Backups should be compressed and uploaded to cloud storage or saved locally.
- Backup can be split into separate files per feature (tables, data, views, functions, procedures, triggers, events) or saved as a single file.
- The default backup includes tables and data only.
Minimum Required Backup Configuration Example
{
"database": {
"host": "localhost",
"user": "root",
"port": 3306,
"db_name": "backy_db"
},
"storage": {
"storage_type": "local"
}
}
Full Backup Configuration Example
{
"database": {
"host": "localhost",
"user": "root",
"port": 3306,
"db_name": "backy_db",
"multiple_files": true,
"features": {
"tables": true,
"data": true,
"views": true,
"functions": true,
"procedures": false,
"triggers": false,
"events": true
}
},
"compression": {
"compression": true,
"compression_type": "tar"
},
"security": {
"encryption": true,
"type": "keystore",
"provider": "local",
"key_size": 4096
},
"integrity": {
"integrity_check": true,
"integrity_type": "hmac"
},
"storage": {
"storage_type": "local"
}
}
Restore Configuration Example
{
"database": {
"host": "localhost",
"user": "root",
"port": 3307,
"db_name": "backy_db"
},
"backup_path": "/path/to/backup/file.backy",
"storage": {
"storage_type": "local"
}
}
Environment Variables
BackyDB supports optional and required environment variables depending on the selected configuration.
-
Required Variables (always required)
DB_PASSWORD=root LOGGING_PATH=/path/to/logs
-
Conditional Variables
-
If encryption is enabled:
PRIVATE_KEY_PASSWORD=private_key_password
-
If using Local Key Store encryption:
LOCAL_KEY_STORE_PATH=/path/to/keys
-
Google Key Store encryption:
GOOGLE_APPLICATION_CREDENTIALS=/path/to/gcp/credentials.json GCP_PROJECT_ID=my-gcp-project
-
If using AWS KMS encryption:
AWS_ACCESS_KEY_ID=your-access-key AWS_SECRET_ACCESS_KEY=your-secret-key AWS_REGION=your-region
-
If using Integrity with HMAC type:
INTEGRITY_PASSWORD=integrity_password
-
If using Local storage:
LOCAL_PATH=/path/to/local/storage
-
If using AWS S3 storage:
AWS_S3_ACCESS_KEY_ID=your-access-key AWS_S3_SECRET_ACCESS_KEY=your-secret-key AWS_S3_BUCKET_NAME=your-bucket-name AWS_S3_REGION=your-region
-
Notes
-
You can customize which database features to backup or restore by enabling/disabling options under features.
-
Storage options currently support local and cloud provider AWS.
-
Compression supports types like tar or zip.
-
Security supports hybrid encryption with local or cloud support key_store (local or GCP) and KMS (AWS).
-
Integrity supports HMAC or checksum validation.
-
You can use YAML or JSON for configuration files.
Basic Example
from backy_db import BackyDB
# Initialize the BackyDB instance
backy_db = BackyDB()
# Define your backup configuration as a dictionary
backup_config = {
"database": {
"host": "localhost",
"user": "root",
"port": 3306,
"db_name": "backy_db",
# Additional optional fields like 'multiple_files' and 'features' can be added
},
"storage": {
"storage_type": "local",
}
}
# Perform a backup
backy_db.backup(backup_config)
# Define your restore configuration as a dictionary
restore_config = {
"database": {
"host": "localhost",
"user": "root",
"port": 3307,
"db_name": "backy_db",
},
"backup_path": "/path/to/backup/file.backy",
"storage": {
"storage_type": "local",
}
}
# Perform a restore
backy_db.restore(restore_config)
Configuration Options
-
Backup supports:
-
Backing up data as raw SQL files (when no compression or encryption is specified).
-
Compressed and/or encrypted backups with a .backy extension.
-
Selecting features to backup such as tables, data, views, functions, procedures, triggers, and events.
-
Splitting backup into multiple files (per feature) or a single file.
-
-
Restore expects:
-
The database connection information.
-
The path to the backup file.
-
Storage details.
-
Refer to the Configuration section for full schema details.
License
BackyDB is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file backy_db-0.1.0.tar.gz.
File metadata
- Download URL: backy_db-0.1.0.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9779670531d5e621bf016cb7c688adc672f1e8be80c9abaa6d2f6c8525811da6
|
|
| MD5 |
08a73e9aeaff314c5e0cb962535fedb0
|
|
| BLAKE2b-256 |
051a53caefea02c309ec26b33bec6b5d5c4dcf40a3af4a99e2a2e26b1996db23
|
File details
Details for the file backy_db-0.1.0-py3-none-any.whl.
File metadata
- Download URL: backy_db-0.1.0-py3-none-any.whl
- Upload date:
- Size: 78.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5eedaa8b0599c19f5790d45f7abb5742b005fcbdead2bb2cbeeae918a487f5e6
|
|
| MD5 |
0c3696bf99eb928a6ba863ffc6289f07
|
|
| BLAKE2b-256 |
0f4e0a9a82408ccc18e4563d59681d076d7c30ebc341f0f1ecf3c176b7aaeb31
|