PGStash CLI
#python#automation#microsaas
Proteggi i tuoi database con PGStash CLI. Backup zero-downtime per PostgreSQL, MySQL e SQLite con crittografia AES-256 lato client e streaming diretto su AWS S3 o Cloudflare R2. Include pruning automatico, test di ripristino e avvisi su Slack, Discord e Telegram. Binari Go pronti per la produzione e template Docker e systemd inclusi.
Leggi l'approfondimento tecnicoAutomatizzare i Backup Cifrati a Zero-Downtime con PGStash CLImain.pymain.py — estratto d'esempio nello stile del tool
#!/usr/bin/env python3
"""
pgstash - Zero-downtime database backup CLI with client-side encryption.
PGStash CLI provides secure, automated backups for PostgreSQL, MySQL, and SQLite.
It streams encrypted archives directly to S3/R2 storage with zero local disk
overhead, automates retention pruning, and dispatches webhook notifications.
Features:
- Zero-downtime streaming backups for PostgreSQL, MySQL, and SQLite
- Client-side AES-256-GCM encryption before stream transmission
- Native S3 and Cloudflare R2 object storage targets
- Automated retention pruning and verification test-restores
- Multi-channel notification alerts for Slack, Discord, and Telegram
Usage:
$ pgstash backup --config /etc/pgstash.toml --engine postgres
$ pgstash restore --backup-id bk_20260330_01 --target-db app_prod
"""
from dataclasses import dataclass
from enum import Enum
from typing import Dict, List, Optional
import logging
import os
import sys
logger = logging.getLogger("pgstash")
class DatabaseEngine(Enum):
"""Supported database engine targets."""
POSTGRESQL = "postgresql"
MYSQL = "mysql"
SQLITE = "sqlite"
@dataclass(frozen=True)
class StorageConfig:
"""Configuration parameters for S3/R2 storage destination."""
endpoint_url: str
bucket_name: str
access_key_id: str
secret_access_key: str
region: str = "us-east-1"
use_ssl: bool = True
class PGStashEngine:
"""Core orchestrator for backup execution, encryption, and streaming."""
def __init__(self, config_path: str) -> None:
self.config_path = config_path
# ... the full file ships with your download