onesystems/dockerbackup

By onesystems

โ€ขUpdated 9 months ago

Backup container for systems that need to have the database and file system backed up

Image
Security
Web servers
Databases & storage
0

100K+

onesystems/dockerbackup repository overview

โ Docker Backup Container

A minimal Alpine-based container to back up directories and databases on a schedule, with notification support via Nextcloud Talk Bot and e-mail.


โ ๐Ÿš€ Features

  • โœ… File backups (tar.gz)
  • โœ… PostgreSQL, MariaDB and MySQL backups (.sql.gz)
  • โœ… Cron-based scheduling
  • โœ… Initial backup on container start
  • โœ… Retention-based cleanup (delete old backups)
  • โœ… Talk Bot notifications (HMAC-based)
  • โœ… Optional e-mail notifications via SMTP
  • โœ… Stale lockfile cleanup (after 1 hour)
  • โœ… Unified logging for file + console (timestamped)
  • โœ… Custom container/service/stack labeling for notifications

โ ๐Ÿ“ฆ Environment Variables

โ ๐Ÿ“ General
VariableDescriptionRequired
FILES_TO_BACKUPSpace-separated list of folders to back upโœ…
BACKUP_DIRRoot folder for all backupsโœ…
LOG_DIRLog file locationโœ…
RETENTION_DAYSDays to keep old backupsโœ…
CRON_SCHEDULECron format (e.g. 0 * * * *)โœ…
STACK_NAMELogical stack name (for identification)โŒ
BACKUP_NAMEFriendly container/service nameโŒ

โ ๐Ÿ›ข๏ธ Database (optional)

Set DB_TYPE=postgres, mariadb, mysql, or none

โ PostgreSQL:
VariableDescription
POSTGRES_HOSTDatabase host
POSTGRES_PORTDatabase port (Standard port 5432 is already set)
POSTGRES_USERUsername
POSTGRES_PASSWORDPassword
POSTGRES_DATABASEDB name
POSTGRES_EXTRA_OPTSExtra options
โ MariaDB:
VariableDescription
MARIADB_HOSTDatabase host
MARIADB_PORTDatabase port (Standard port 3306 is already set)
MARIADB_USERUsername
MARIADBYSQL_PASSWORDPassword
MARIADB_DATABASEDB name
MARIADB_EXTRA_OPTSExtra options
โ MySQL:
VariableDescription
MYSQL_HOSTDatabase host
MYSQL_PORTDatabase port (Standard port 3306 is already set)
MYSQL_USERUsername
MYSQL_PASSWORDPassword
MYSQL_DATABASEDB name
MYSQL_EXTRA_OPTSExtra options

โ ๐Ÿ’ฌ Nextcloud Talk Bot (HMAC)
VariableDescription
NC_TALK_NOTIFY=onEnable Talk Bot notifications
NC_TALK_URLNextcloud base URL
NC_TALK_BOT_CHANNELBot ID or room token (from Talk or occ)
NC_TALK_BOT_SECRETShared secret (from php occ talk:bot:install)

โ ๐Ÿ“ง Email Notifications (optional)
VariableDescription
EMAIL_NOTIFY=onEnable e-mail alerts
EMAIL_TORecipient
EMAIL_FROMSender
SMTP_SERVERSMTP hostname/IP
SMTP_PORTPort (default: 587)
SMTP_USERSMTP user (if auth needed)
SMTP_PASSSMTP password
SMTP_TLS=onEnable STARTTLS (default: on)

๐Ÿ“ฆ Uses msmtp (included) for sending mail


โ ๐Ÿงช Example docker-compose.yml

version: '3'

services:
  backup:
    build: .
    environment:
      FILES_TO_BACKUP: "/data"
      BACKUP_DIR: "/backup"
      LOG_DIR: "/log"
      RETENTION_DAYS: 30
      CRON_SCHEDULE: "0 * * * *"

      BACKUP_NAME: "web-backup-db"

      DB_TYPE: "postgres"
      POSTGRES_HOST: "postgres"
      POSTGRES_USER: "backupuser"
      POSTGRES_PASSWORD: "secret"
      POSTGRES_DATABASE: "myapp"

      NC_TALK_NOTIFY: "off"
      NC_TALK_URL: "https://cloud.example.com"
      NC_TALK_BOT_CHANNEL: "abc123"
      NC_TALK_BOT_SECRET: "your_shared_hmac_secret"

      EMAIL_NOTIFY: "off"
      EMAIL_TO: "[email protected]"
      EMAIL_FROM: "[email protected]"
      SMTP_SERVER: "smtp.example.com"
      SMTP_PORT: 587
      SMTP_USER: "smtp-user"
      SMTP_PASS: "smtp-pass"
      SMTP_TLS: "on"

    volumes:
      - ./data:/data
      - ./backup:/backup
      - ./log:/log

โ ๐Ÿ“‚ Folder Structure

/backup/
  2025-04/
    files_data_2025-04-30_1400.tar.gz
    postgres_myapp_2025-04-30_1400.sql.gz
/log/
  backup_2025-04-30.log

โ ๐Ÿงน Cleanup

Backups older than RETENTION_DAYS are removed automatically. Log entries show deleted files.


โ ๐Ÿฉบ Healthcheck (optional)

Add this to your Compose file to track success:

healthcheck:
  test: ["CMD", "/scripts/healthcheck.sh"]
  interval: 5m
  timeout: 10s
  retries: 3
  start_period: 30s

The backup script writes this file only on success


โ ๐Ÿง‘โ€๐Ÿ’ป Author


โ ๐Ÿ“ License

MIT License โ€“ free for commercial and private use.

Tag summary

Content type

Image

Digest

sha256:18ca488c4โ€ฆ

Size

26.1 MB

Last updated

9 months ago

docker pull onesystems/dockerbackup