Litestream replication to the NAS and nightly media backup
CI / ci (pull_request) Successful in 1m38s
CI / ci (push) Successful in 1m34s

Add a litestream service (0.5.17) to the compose stack that streams
/data/mealquest.db over SFTP to the Synology NAS with a dedicated key,
daily snapshots kept for a week. Add a systemd timer that rsyncs the
media directory to the NAS nightly at 03:30.

Task: d2f2e87e-5114-4ef1-93ab-360ffb5c009e

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 19:15:16 -04:00
co-authored by Claude Opus 5.5
parent 9d0e943fc3
commit 9ac3342664
5 changed files with 131 additions and 0 deletions
@@ -0,0 +1,13 @@
# Runs the nightly MealQuest media backup (/usr/local/sbin/mealquest-media-backup).
# Triggered by mealquest-media-backup.timer; run by hand with
# systemctl start mealquest-media-backup
# and read the result with
# journalctl -u mealquest-media-backup
[Unit]
Description=Back up MealQuest media to the Synology NAS
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/mealquest-media-backup
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# Nightly copy of the MealQuest media directory (recipe and dinner photos)
# to the Synology NAS. The database itself is replicated continuously by
# Litestream; this covers the files beside it.
#
# rsync mirrors the media directory onto .../mealquest-backups/media/ only:
# both paths end in a slash, so --delete removes files from that target
# directory and nothing outside it. A missing source directory (no media
# uploaded yet) is reported and skipped, never synced, so an empty source
# can never wipe the remote copy. Re-runs transfer only what changed.
#
# The volume is writable by the app container, so a media path that is a
# symlink is refused: root's rsync would otherwise follow it and copy
# whatever it points at. Symlinks inside the directory are copied as links
# (-a), never followed.
#
# Connects with the dedicated MealQuest key; the NAS host key must already
# be in root's known_hosts (StrictHostKeyChecking=yes fails otherwise).
# Installed as /usr/local/sbin/mealquest-media-backup; output goes to the
# journal via mealquest-media-backup.service.
set -eu
src=/var/lib/docker/volumes/mealquest-data/_data/media/
dest=joshua@10.60.1.50:/volume1/homes/Joshua/mealquest-backups/media/
key=/home/overseer/mealquest/deploy/secrets/litestream_key
if [ -L "${src%/}" ]; then
echo "mealquest-media-backup: ${src%/} is a symlink; refusing to back it up" >&2
exit 1
fi
if [ ! -d "$src" ]; then
echo "mealquest-media-backup: no media directory at $src yet; nothing to back up"
exit 0
fi
rsync -a --delete --stats \
-e "ssh -i $key -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes" \
"$src" "$dest"
echo "mealquest-media-backup: synced $src to $dest"
@@ -0,0 +1,11 @@
# Nightly trigger for mealquest-media-backup.service. Persistent= runs a
# missed backup at the next boot.
[Unit]
Description=Nightly MealQuest media backup
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
[Install]
WantedBy=timers.target