Skip to content

Repository files navigation

Backup scripts

A Python backup orchestration tool. Given a JSON configuration file, it cycles through sources (databases, folders, cloud snapshots), compresses and optionally encrypts each backup, uploads to one or more destinations, and reports via notifications.

Quick start

pip install backups
backups /etc/backups/production.json

See docs/scheduling.md for how to run as a systemd timer or cron job.

Configuration

Configuration is a single JSON file:

{
"sources": [ ... ],
"destinations": [ ... ],
"notifications": [ ... ]
}

Encryption (optional)

Encryption can be specified at the top level (applies to all sources) or per-source. Per-source settings override top-level.

Top-level (applies to all sources):

{
"encryption": {
"passphrase": "YOUR_PASSPHRASE"
},
"sources": [...]
}

Or per-source:

{
"sources": [
{
"name": "mysql-db",
"type": "mysql",
"passphrase": "YOUR_PASSPHRASE"
},
{
"name": "pg-db",
"type": "postgresql",
"recipients": ["ops@example.com"]
}
]
}

Use passphrase for symmetric GPG encryption, or recipients (array) for asymmetric/GPG public key encryption.

Override semantics: if a source defines either passphrase or recipients, the top-level encryption block is ignored entirely for that source.

Note: older configs containing "type": "symmetric" or "type": "asymmetric" fields in the encryption block should be updated — those fields were never implemented and are ignored.

Tracing Configuration

OpenTelemetry OTLP tracing is supported for observability. Tracing is disabled by default (zero performance impact).

Install the optional tracing dependencies:

pip install backups[tracing]

To enable tracing:

  • Set OTEL_EXPORTER_OTLP_ENDPOINT to your OTLP collector URL (e.g., http://localhost:4317 for gRPC).
  • Optional: Set OTEL_EXPORTER_OTLP_HEADERS for authentication (e.g., authorization=Bearer token).
  • Optional: Set OTEL_EXPORTER_OTLP_INSECURE=true to disable TLS (default: TLS enabled).
  • Optional: Set OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG to control sampling (e.g., OTEL_TRACES_SAMPLER=traceidratio and OTEL_TRACES_SAMPLER_ARG=0.1 for 10%).

Example:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
backups /etc/backups/production.json

Traces include comprehensive spans for:

  • Backup run - version, hostname
  • Per-source processing - source ID, type, name
  • Dump operations - database host/name, file paths, operation timing
  • Compression/encryption - operation type, input/output files
  • Destination uploads - per-destination spans with upload locations (S3, GDrive, Minio, etc.)
  • Retention cleanup - object counts, retained/removed counts
  • Notifications - notification type, source ID

All spans include relevant metadata (file paths, database names, bucket names, object counts, timing, errors). The cloudflare-backup-registry notification automatically includes the current trace ID in its metadata for end-to-end correlation.

Sources

TypeDescriptionDocs
folderLocal directory via tardocs/sources/folder.md
folder-sshRemote directory via SSH + tardocs/sources/folderssh.md
sftp-folderRemote directory via SFTPdocs/sources/sftpfolder.md
mysqlMySQL/MariaDB via mysqldumpdocs/sources/mysql.md
mysql-sshMySQL via SSH tunneldocs/sources/mysqlssh.md
postgresqlPostgreSQL via pg_dumpdocs/sources/postgresql.md
rdsAWS RDS MySQL snapshotdocs/sources/rds.md
rds-pgsqlAWS RDS PostgreSQL snapshotdocs/sources/rdspostgresql.md
snapshotAzure Managed Disk snapshotdocs/sources/snapshot.md
lvm-sshLVM snapshot over SSHdocs/sources/lvm-ssh.md

Destinations

TypeDescriptionDocs
s3AWS S3 bucketdocs/destinations/s3.md
gsGoogle Cloud Storagedocs/destinations/gs.md
b2Backblaze B2docs/destinations/b2.md
minioMinio / S3-compatible (DO Spaces, Wasabi, etc.)docs/destinations/minio.md
dropboxDropboxdocs/destinations/dropbox.md
gdriveGoogle Drivedocs/destinations/gdrive.md
localLocal filesystem path (NFS, USB, etc.)docs/destinations/local.md
sambaSamba/CIFS sharedocs/destinations/samba.md

All destinations support retention_copies and/or retention_days to automatically prune old backups.

Notifications

TypeDescriptionDocs
smtpEmail via SMTPdocs/notifications/smtp.md
slackSlack Incoming Webhookdocs/notifications/slack.md
discordDiscord webhookdocs/notifications/discord.md
telegramTelegram Bot APIdocs/notifications/telegram.md
matrixMatrix room messagedocs/notifications/matrix.md
flagfileWrite a flag file for monitoringdocs/notifications/flagfile.md
prometheusPush metrics to Prometheus Pushgatewaydocs/notifications/prometheus.md
elasticsearchWrite stats documents to Elasticsearchdocs/notifications/elasticsearch.md
cloudflare-backup-registryBackup run reports to Cloudflare Backup Registrydocs/notifications/cloudflare-backup-registry.md

Scheduling

See docs/scheduling.md for setup with:

  • systemd timer (recommended) — structured logging, dependency management, easy monitoring
  • cron — simple alternative

Development

pip install -r requirements-dev.txt
pytest tests/ -v

Docker

docker pull ghcr.io/rossigee/backups:latest
docker run --rm -v /etc/backups:/etc/backups ghcr.io/rossigee/backups:latest /etc/backups/production.json

About

A small/simple python script to back up folders and databases.

Resources

Stars

14 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages