Files
ytplayer/scripts/ops/uploads-backup.sh
Jonathan Sykes 11ddb8a970 Uploads library on the USB drive with a nightly stable-disk copy; Topic channels resolve by name
- UPLOAD_DIR moves to the USB drive; reads fall back to UPLOAD_BACKUP_DIR on the
  ytplayer-data volume, and while the drive is offline new uploads land there
- scripts/ops/uploads-backup.sh (homelab cron, 03:30) copies both ways, never
  deletes; the server removes a deleted upload from both places
- /api/channel resolves a bare channel name ('Artist - Topic') to its id via a
  search, and the client falls back to the channel name for old saved entries
2026-10-02 22:38:05 +08:00

30 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Nightly second copy of the ytplayer uploads library (homelab host, cron).
#
# USB drive (primary): /mnt/data/ytplayer/uploads
# stable disk (backup): <ytplayer-data volume>/uploads-backup
#
# Copies new files both ways and never deletes: the server removes a deleted
# upload from both places itself, and anything uploaded while the drive was
# offline (written to the backup) is copied back onto the drive here.
set -eu
VOL=${VOL:-/var/lib/docker/volumes/ytplayer-main-1dihzn_ytplayer-data/_data}
USB=/mnt/data/ytplayer
MIN_FREE_KB=${MIN_FREE_KB:-20971520} # keep 20 GiB free on the stable disk
log() { logger -t ytplayer-uploads-backup "$*"; echo "$*"; }
[ -f "$USB/.hl-data" ] || { log "USB drive offline (no marker) — skipped"; exit 0; }
mkdir -p "$USB/uploads" "$VOL/uploads-backup"
need=$(du -sk "$USB/uploads" | cut -f1)
have=$(du -sk "$VOL/uploads-backup" | cut -f1)
free=$(df -Pk "$VOL" | awk 'NR==2{print $4}')
if [ $((free - (need - have))) -lt "$MIN_FREE_KB" ]; then
log "not enough room on the stable disk for the backup (free ${free} KB, need ~$((need - have)) KB more) — skipped"
exit 1
fi
rsync -a --update "$USB/uploads/" "$VOL/uploads-backup/" # newer wins (e.g. replaced cover art)
rsync -a --update "$VOL/uploads-backup/" "$USB/uploads/"
log "ok — $(ls "$USB/uploads" | wc -l) files, $(du -sh "$USB/uploads" | cut -f1)"