I'm trying to come up with a elegant way of backing up my docker volumes. I don't really care about my host and the data on the host, because everything I do happens inside my docker containers and the mapped volumes. Some containers use mapped paths, but some others use straight up docker volumes.

I've started writing a script that inspects the containers, reads all the mount paths and then spins up another container to tar all the mounted paths.

docker run --rm --volumes-from $container_name-v /data/backup:/backup busybox tar cvf /backup/$container_name.tar $paths

So far so good, this works and I can write all backups to my storage and later sync them to an offsite backup space.

But error handling, (nice)logging and notifications using ntfy in case of success / errors / problems is going to suck in a bash script. Local backup file rollover and log file rollover also just suck if I have to do all this by hand. I'm able to use other languages to write this backup util but I don't want to start this project if there already is a ready made solution.

So the question, is there a utility that can simply schedule arbitrary bits of script, write nicer logs for these script bits, do file rollovers and run another script on success / error?
All the backup programs that I can find are more focused on backing up directories, permissions and so on.

you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 2 years ago*

I made my own solution since I wasn't impressed by projects I had found. There's two parts, the backup image and the restore image.

I use it like so:

services:
  restore_sabnzbd:
    image: untouchedwagons/simple-restore:1.0.5
    container_name: restore_sabnzbd
    restart: no
    environment:
      - BACKUP_APPEND_DIRECTORY=/docker/production/sabnzbd
      - BACKUP_BASE_NAME=sabnzbd
      - FORCE_OWNERSHIP=1000:1000
    volumes:
      - sabnzbd:/data
      - /mnt/tank/Media/Backups:/backups

  sabnzbd:
    image: ghcr.io/onedr0p/sabnzbd:4
    container_name: sabnzbd
    restart: unless-stopped
    user: 1000:1000
    volumes:
      - sabnzbd:/config
      - /mnt/tank/Media/Usenet:/mnt/data/Usenet
    depends_on:
      restore_sabnzbd:
        condition: service_completed_successfully
    networks:
      - traefik_default

  backup_sabnzbd:
    image: untouchedwagons/simple-backup:1.1.0
    container_name: backup_sabnzbd
    restart: unless-stopped
    environment:
      TZ: "America/Toronto"
      BACKUP_APPEND_DIRECTORY: "/docker/production/sabnzbd"
      BACKUP_BASE_NAME: "sabnzbd"
      BACKUP_RETENTION: "24"
      BACKUP_FREQUENCY: "0 0 * * *"
    volumes:
      - sabnzbd:/data:ro
      - /mnt/tank/Media/Backups:/backups
      
networks:
  traefik_default:
    external: true

volumes:
  sabnzbd:

The restore container looks for a file called RESTORED in /data and if one isn't found it'll try to restore the latest backup (if available) and then create a RESTORED file. The backup container ignores this file during backup.

  • source