I've been living on the edge and not backing up my persistent volumes for all of my docker containers. For most of them this isn't really a problem. It would be annoying, but not all that bad if I lost the jellyfin database.

However, other containers like Vaultwarden have critical data within them, and having backups is important.

I've played around with some of the backup solutions that can be run as docker containers themselves (restic, kopia) and came away thinking that most of of them are neat but overkill for me.

Instead, I just wrote a bash script to stop all of the docker containers. For most of the containers the folders are not very large anyway and I end up with a backup file around 1.5 GB.

#!/usr/bin/env bash

# Remove all files older than 5 days
#find /mnt/nas/backup/* -type f -mtime +5 -exec rm {} \;

# Get today's date for the backup filename
backupDate=$(date +'%F')

# move to the 'docker' folder containing all the persistent volumes
cd /opt/docker

# stop the docker containers for the HTPC stack
docker compose stop

# stop nginx-proxy-manager
cd /opt/docker/nginx-proxy-manager
docker compose stop

# stop audiobookshelf
cd /opt/docker/audiobookshelf
docker compose stop

# stop vaultwarden
cd /opt/docker/vaultwarden
docker compose stop

# stop freshrss
cd /opt/docker/freshrss
docker compose stop

# stop calibre-web
cd /opt/docker/calibre-web
docker compose stop

# stop calibre
cd /opt/docker/calibre
docker compose stop

# stop diun
cd /opt/docker/diun
docker compose stop

# move back to parent directory and create a tar archive of the folder
cd /opt
tar -czvf docker-backup-$backupDate.tar.gz /opt/docker

# start the HTPC stack
cd /opt/docker
docker compose up -d

cd /opt/docker/nginx-proxy-manager
docker compose up -d

cd /opt/docker/audiobookshelf
docker compose up -d

cd /opt/docker/vaultwarden
docker compose up -d

cd /opt/docker/freshrss
docker compose up -d

cd /opt/docker/calibre-web
docker compose up -d

# not restarting calibre. It is only started when needed

cd /opt/docker/diun
docker compose up -d

# now go back to 'docker' folder and copy the backup file to the NAS
cd /opt
echo ""
echo "Backup copy is running..."

# use scp to copy the tar archive to the NAS
scp docker-backup-$backupDate.tar.gz /mnt/nas/backup

# remove the tar file from the docker folder after it is copied
rm docker-backup-$backupDate.tar.gz