Stashly is a powerful, automated PostgreSQL backup tool with cloud storage support. It provides scheduled backups, encryption, and seamless integration with S3-compatible storage backends.
- Automated PostgreSQL Backups: Schedule recurring backups using cron expressions
- Cloud Storage Integration: Upload backups to S3-compatible storage (AWS S3, MinIO, etc.)
- GPG Encryption: Optional GPG encryption for enhanced security
- Smart Retention Policy: Automatically manage backup retention and cleanup
- Discord Notifications: Get notified of backup success/failure via Discord webhooks
- Docker Support: Ready-to-use Docker images for easy deployment
- CLI Interface: Simple command-line interface with immediate backup triggers
- Multi-Database Support: Automatically detect and backup all non-template databases
- Go 1.24.4+ (for building from source)
- PostgreSQL client tools (
psql,pg_dump) - S3-compatible storage (AWS S3, MinIO, etc.)
- GPG key server (if using encryption)
# Clone the repository
git clone https://github.com/hibare/stashly.git
cd stashly
# Build the binary
go build -o stashly main.go
# Install to system PATH (optional)
sudo cp stashly /usr/local/bin/# Pull the official image
docker pull hibare/stashly
# Or build locally
docker build -t stashly .Stashly uses YAML configuration files. Create a config file at /etc/stashly/config.yaml or specify a custom path.
# PostgreSQL connection settings
postgres:
host: "localhost"
port: "5432"
user: "postgres"
password: "your_password"
# S3 storage configuration
s3:
endpoint: "https://s3.amazonaws.com" # or your S3-compatible endpoint
region: "us-east-1"
access-key: "your_access_key"
secret-key: "your_secret_key"
bucket: "your_backup_bucket"
prefix: "postgres_backups"
# Backup settings
backup:
retention-count: 30 # Number of backups to retain
cron: "0 0 * * *" # Cron schedule (daily at midnight)
encrypt: false # Enable GPG encryption
# GPG encryption (if enabled)
encryption:
gpg:
key-server: "keyserver.ubuntu.com"
key-id: "your_gpg_key_id"
# Notifications
notifiers:
enabled: true
discord:
enabled: true
webhook: "your_discord_webhook_url"
# Logging
logger:
level: "info"
mode: "json"All configuration options can be set via environment variables using the STASHLY_ prefix:
export STASHLY_POSTGRES_HOST=localhost
export STASHLY_POSTGRES_PORT=5432
export STASHLY_POSTGRES_USER=postgres
export STASHLY_POSTGRES_PASSWORD=your_password
export STASHLY_S3_ENDPOINT=https://s3.amazonaws.com
export STASHLY_S3_REGION=us-east-1
export STASHLY_S3_ACCESS_KEY=your_access_key
export STASHLY_S3_SECRET_KEY=your_secret_key
export STASHLY_S3_BUCKET=your_backup_bucket
export STASHLY_S3_PREFIX=postgres_backups
export STASHLY_BACKUP_CRON="0 0 * * *"
export STASHLY_BACKUP_RETENTION_COUNT=30
export STASHLY_BACKUP_ENCRYPT=false
export STASHLY_NOTIFIERS_DISCORD_WEBHOOK=your_discord_webhook_urlStashly provides a simple CLI with the following commands:
# Start scheduled backups (default behavior)
stashly
# Trigger an immediate backup
stashly backup
# Use custom config file
stashly --config /path/to/config.yaml
# Start with scheduled backups
stashly --config /path/to/config.yaml# Run with custom config
docker run -v /path/to/config:/etc/stashly/config.yaml hibare/stashly
# Run with environment variables
docker run \
-e STASHLY_POSTGRES_HOST=host.docker.internal \
-e STASHLY_POSTGRES_USER=postgres \
-e STASHLY_POSTGRES_PASSWORD=password \
-e STASHLY_S3_ENDPOINT=https://s3.amazonaws.com \
-e STASHLY_S3_REGION=us-east-1 \
-e STASHLY_S3_ACCESS_KEY=your_key \
-e STASHLY_S3_SECRET_KEY=your_secret \
-e STASHLY_S3_BUCKET=backups \
hibare/stashlyversion: "3.9"
services:
stashly:
image: hibare/stashly
container_name: stashly
volumes:
- ./config:/etc/stashly
environment:
- STASHLY_POSTGRES_HOST=postgres
- STASHLY_POSTGRES_USER=postgres
- STASHLY_POSTGRES_PASSWORD=password
networks:
- db
depends_on:
- postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
networks:
db:
driver: bridge- Go 1.24.4+
- Docker and Docker Compose
- PostgreSQL client tools
# Clone the repository
git clone https://github.com/hibare/stashly.git
cd stashly
# Initialize development environment
make init
# Start development services (PostgreSQL + MinIO)
make dev
# Run tests
make test
# Clean up
make cleanstashly/
βββ cmd/ # Command-line interface
β βββ backup.go # Backup command implementation
β βββ common.go # Common functionality
β βββ root.go # Root command and scheduling
βββ internal/ # Internal packages
β βββ assets/ # Application assets (logo, etc.)
β βββ config/ # Configuration management
β βββ constants/ # Application constants
β βββ dumpster/ # PostgreSQL dump functionality
β βββ exec/ # Command execution interface
β βββ notifiers/ # Notification services
β β βββ discord/ # Discord notification implementation
β βββ storage/ # Storage backends
β βββ s3/ # S3 storage implementation
βββ testhelpers/ # Test utilities
βββ docker-compose.yml # Production Docker setup
βββ docker-compose.dev.yml # Development environment
βββ Dockerfile # Multi-stage Docker build
βββ Makefile # Development tasks
βββ main.go # Application entry point
# Build for current platform
go build -o stashly main.go
# Build for specific platform
GOOS=linux GOARCH=amd64 go build -o stashly main.go
# Build with Docker
docker build -t stashly .# Run all tests
make test
# Run tests with coverage
go test ./... -cover
# Run specific package tests
go test ./internal/dumpster/...- Pre-flight Checks: Verify PostgreSQL tools availability and create temporary directories
- Database Discovery: Automatically detect all non-template databases
- Dump Creation: Create SQL dumps using
pg_dumpfor each database - Archive Creation: Compress all dumps into a single archive
- Encryption (optional): Encrypt the archive using GPG if enabled
- Upload: Upload to configured storage backend
- Cleanup: Remove temporary files and old backups based on retention policy
- Notification: Send success/failure notifications via configured notifiers
- GPG Encryption: Optional GPG encryption for backup files
- Secure Storage: Support for S3-compatible storage with access controls
- Environment Variables: Secure configuration via environment variables
- Temporary Files: Automatic cleanup of temporary backup files
Stashly can send notifications to Discord channels via webhooks:
- Backup Success: Database count and storage location
- Backup Failure: Error details and failure information
- Cleanup Failure: Retention policy cleanup errors
Comprehensive logging with configurable levels:
- JSON Mode: Structured logging for production environments,
PRETTY/JSON - Text Mode: Human-readable logs for development
- Configurable Levels: Debug, Info, Warn, Error,
DEBUG/INFO/ERROR
The project includes a complete development environment with:
- PostgreSQL 16: Database server for testing
- MinIO: S3-compatible object storage
- Pre-configured buckets: Ready-to-use storage buckets
- Network isolation: Secure development environment
Start the development environment:
make devThis will start PostgreSQL on port 5432 and MinIO on ports 9000 (API) and 9001 (Console).
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request