Skip to content

SemmiDev/phylax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Phylax - Advanced Multi-Target Database Backup System

Production-ready automated backup solution with support for multiple databases and multiple upload destinations.

✨ Features

Database Support

  • βœ… MySQL - Full mysqldump with routines, triggers, events
  • βœ… PostgreSQL - pg_dump with custom format and SSL support
  • βœ… MongoDB - mongodump with gzip and authentication
  • βœ… Multiple Connections - Backup multiple databases with different schedules

Upload Destinations

  • βœ… Local Storage - Always enabled
  • βœ… Google Drive - OAuth2 integration
  • βœ… AWS S3 - With pagination support for large buckets
  • βœ… Azure Blob Storage - Full SDK integration
  • βœ… SFTP/SCP - Password or private key authentication
  • βœ… Telegram - Notifications and file uploads
  • βœ… Parallel Uploads - All destinations upload simultaneously with retry

Compression & Encryption

  • βœ… Gzip - Standard compression (default)
  • βœ… Zstandard - Better ratio, fast compression
  • βœ… LZ4 - Ultra-fast compression
  • βœ… AES-256-GCM - Optional backup encryption

Observability

  • βœ… Prometheus Metrics - backup_duration, backup_size, success/failure counts
  • βœ… Web API - /health, /status, /history, /trigger/:db, /metrics
  • βœ… Health Checks - Database and storage connectivity monitoring

Notifications

  • βœ… Email - SMTP with HTML templates
  • βœ… Slack - Webhook integration
  • βœ… Discord - Webhook integration
  • βœ… Telegram - Bot notifications

Core Features

  • βœ… SHA256 Verification - Backup integrity checksums
  • βœ… Retry with Backoff - Automatic upload retries
  • βœ… Pre/Post Hooks - Custom shell scripts
  • βœ… Retention Policy - Automatic cleanup per-target
  • βœ… Restore Command - Restore backups to databases
  • βœ… Graceful Shutdown - Proper cleanup

πŸ“¦ Installation

Prerequisites

# Database clients
sudo apt install mysql-client postgresql-client mongodb-clients

# Or on macOS
brew install mysql-client postgresql mongodb-community

Build & Install

# Clone repository
git clone https://github.com/semmidev/phylax
cd phylax

# Install dependencies
make deps

# Build
make build

# Install as service
sudo make install

βš™οΈ Configuration

Basic Configuration

app:
  name: 'phylax'
  port: 8089
  log_level: 'info'
  log_file: 'log/phylax/backup.log'

# Web API (optional)
api:
  enabled: true
  port: 8080

databases:
  - name: 'production-mysql'
    type: 'mysql'
    host: 'localhost'
    port: 3306
    username: 'backup'
    password: 'secret'
    database: 'myapp'
    enabled: true
    schedule: '0 0 2 * * *' # 2 AM daily
    timeout: 3600s

  - name: 'analytics-postgres'
    type: 'postgresql'
    host: 'db.example.com'
    port: 5432
    username: 'postgres'
    password: 'secret'
    database: 'analytics'
    ssl_mode: 'require'
    enabled: true
    schedule: '0 0 3 * * *'

  - name: 'logs-mongodb'
    type: 'mongodb'
    host: 'mongo.example.com'
    port: 27017
    username: 'admin'
    password: 'secret'
    database: 'logs'
    auth_database: 'admin'
    enabled: true
    schedule: '0 0 4 * * *'

backup:
  retention_days: 14
  compress: true
  verify: true
  retry_attempts: 3

  compression:
    algorithm: 'zstd' # gzip, zstd, lz4
    level: 6

  encryption:
    enabled: true
    algorithm: 'AES-256-GCM'
    key_file: '/etc/phylax/encryption.key'

  upload_targets:
    - type: 'local'
      enabled: true
      path: '/var/backups/databases'
      retention_days: 7

    - type: 's3'
      enabled: true
      region: 'us-east-1'
      bucket: 'company-backups'
      access_key: 'AKIA...'
      secret_key: '...'
      prefix: 'databases/'
      retention_days: 90

    - type: 'azure'
      enabled: true
      account_name: 'mystorageaccount'
      account_key: '...'
      container_name: 'backups'

    - type: 'sftp'
      enabled: true
      sftp_host: 'backup.example.com'
      sftp_port: 22
      sftp_username: 'backup'
      sftp_private_key: '/etc/phylax/sftp.key'
      sftp_remote_path: '/backups'

notifications:
  email:
    enabled: true
    smtp_host: 'smtp.gmail.com'
    smtp_port: 587
    username: 'alerts@company.com'
    password: '...'
    from: 'backups@company.com'
    recipients: ['ops@company.com']
    on_failure: true

  slack:
    enabled: true
    webhook_url: 'https://hooks.slack.com/...'
    channel: '#backup-alerts'
    on_success: true
    on_failure: true

πŸš€ Usage

Service Management

# Start service
sudo systemctl start phylax

# Enable on boot
sudo systemctl enable phylax

# Check status
sudo systemctl status phylax

# View logs
sudo journalctl -u phylax -f

API Endpoints

# Health check
curl http://localhost:8080/health

# Get status
curl http://localhost:8080/status

# View backup history
curl http://localhost:8080/history

# Trigger manual backup
curl -X POST http://localhost:8080/trigger/production-mysql

# Prometheus metrics
curl http://localhost:8080/metrics

Restore Command

# Restore a backup
phylax-restore \
  --file /var/backups/databases/mydb_mysql_20240115_020000.sql.gz \
  --database production-mysql \
  --config /etc/phylax/config.yaml

# Dry run (simulate)
phylax-restore --file backup.sql.gz --database mydb --dry-run

πŸ“Š Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Scheduled Triggers                        β”‚
β”‚  2 AM: MySQL  |  3 AM: PostgreSQL  |  4 AM: MongoDB          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                  β”‚                  β”‚
               β–Ό                  β–Ό                  β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Backup  β”‚       β”‚  Backup  β”‚      β”‚  Backup  β”‚
        β”‚  MySQL   β”‚       β”‚PostgreSQLβ”‚      β”‚ MongoDB  β”‚
        β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
              β”‚                  β”‚                  β”‚
              β–Ό                  β–Ό                  β–Ό
      [Compress: gzip/zstd/lz4] + [Encrypt: AES-256-GCM]
              β”‚                  β”‚                  β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚  Parallel Uploads      β”‚
                     β”‚  (with retry logic)    β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Local   β”‚   S3     β”‚  Azure   β”‚  GDrive  β”‚  SFTP    β”‚
    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚    Notifications       β”‚
                     β”‚ Email | Slack | Discordβ”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Security

Password Protection

  • Database passwords use environment variables (not command-line args)
  • Config file should have restricted permissions (chmod 600)

Encryption

# Generate encryption key
openssl rand -base64 32 > /etc/phylax/encryption.key
chmod 600 /etc/phylax/encryption.key

Database User Permissions

-- MySQL: Create dedicated backup user
CREATE USER 'backup'@'%' IDENTIFIED BY 'secure_password';
GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'backup'@'%';

-- PostgreSQL
CREATE USER backup WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE mydb TO backup;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO backup;

πŸ“ˆ Metrics

Prometheus metrics available at /metrics:

Metric Description
phylax_backup_duration_seconds Backup duration histogram
phylax_backup_size_bytes Backup file size
phylax_backup_success_total Successful backup counter
phylax_backup_failure_total Failed backup counter
phylax_upload_duration_seconds Upload duration histogram
phylax_upload_success_total Successful upload counter
phylax_upload_failure_total Failed upload counter
phylax_last_backup_timestamp Last successful backup time

πŸ§ͺ Testing

# Run all tests
make test

# With coverage
go test -v -cover ./...

🀝 Contributing

Contributions welcome! Please ensure:

  1. Tests pass: make test
  2. Code formatted: go fmt ./...
  3. Linting clean: golangci-lint run

πŸ“„ License

MIT License - see LICENSE file

πŸ™ Acknowledgments

Built with:


Made with ❀️ for reliable database backups

About

Advanced Multi-Target Database Backup System. Production-ready automated backup solution with support for multiple databases and multiple upload destinations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors