Sign inSign up

zachbg/docker-volume-backup

By zachbg

•Updated 6 months ago

Backup and restore Docker named volumes with S3 upload and retention

Image
1

2.3K

zachbg/docker-volume-backup repository overview

⁠Docker Volume Backup

Backup and restore Docker named volumes with one command. Supports scheduled backups, S3 upload, retention policies, and container stop/start around backup windows.

⁠Why?

docker-compose down -v deletes all your data. A corrupted volume is gone forever. Docker has zero built-in volume backup. This image fixes that.

⁠Quick Start

⁠One-time backup
docker run --rm \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ./backups:/backup \
  -e VOLUMES=myapp_data,myapp_db \
  zachbg/docker-volume-backup:latest
⁠Scheduled backup (every 6 hours)
services:
  vol-backup:
    image: zachbg/docker-volume-backup:latest
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./backups:/backup
    environment:
      VOLUMES: myapp_data,myapp_db
      SCHEDULE: 21600
      RETENTION_DAYS: 7
⁠Restore
docker run --rm \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ./backups:/backup \
  -e RESTORE_FILE=myapp_db_20250115_120000.tar.gz \
  -e RESTORE_VOLUME=myapp_db \
  zachbg/docker-volume-backup:latest restore

⁠Environment Variables

VariableDefaultDescription
VOLUMESComma-separated volume names to backup
LABELvol-backup.enableOr use labels to select volumes
BACKUP_DIR/backupLocal backup directory
SCHEDULEBackup interval in seconds (empty = one-shot)
COMPRESStrueGzip compress backups
TIMESTAMPtrueAdd timestamp to filenames
RETENTION_DAYS7Delete backups older than N days
STOP_CONTAINERSComma-separated containers to stop during backup
S3_BUCKETUpload backups to S3/R2
S3_PREFIXdocker-volumesS3 key prefix
AWS_ENDPOINT_URLCustom S3 endpoint
PRE_HOOKCommand to run before backup
POST_HOOKCommand to run after backup
WEBHOOK_URLNotification webhook

⁠Examples

⁠Stop database before backup
environment:
  VOLUMES: postgres_data
  STOP_CONTAINERS: postgres
  SCHEDULE: 86400
⁠Backup to Cloudflare R2
environment:
  VOLUMES: app_data
  S3_BUCKET: my-backups
  AWS_ACCESS_KEY_ID: xxx
  AWS_SECRET_ACCESS_KEY: xxx
  AWS_ENDPOINT_URL: https://account.r2.cloudflarestorage.com
  SCHEDULE: 21600
⁠Label-based selection
services:
  vol-backup:
    image: zachbg/docker-volume-backup:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./backups:/backup

volumes:
  app_data:
    labels:
      vol-backup.enable: "true"
  cache_data:
    # This volume won't be backed up

Tag summary

Content type

Image

Digest

sha256:93ba46fc2…

Size

53.1 MB

Last updated

6 months ago

docker pull zachbg/docker-volume-backup