source: Klonkt/deploy/backup.sh@ 9b36f45

main
Last change on this file since 9b36f45 was b5bae24, checked in by Robin Genis <roboburr@…>, 3 months ago

reconcile: commit uncommitted live /srv state (playback fix + prefetch, SF favicon, smooth scroll, scripts)

The live working tree /srv/prutfolio was ahead of the bare repo with direct
server edits that had never been committed back. The deploy hook does
checkout -f main, so the next deploy would have reverted the 3 modified
tracked files to f33db01 and lost this work:

  • audio-player.js: robust playback — retry+backoff on network hiccups (no longer skipping immediately) + next-track prefetch (downloads the next track while the current one plays -> ended->next swaps instantly, covering the autoplay lapse). Fix for the sometimes-next-doesn't-play bug.
  • server.js: favicon mark p -> SF (SoundFabrics rebrand). shell.ejs: audio-player.js cache buster ?v=5 -> ?v=6 + favicon ?v=sf.
  • Plus previously untracked project files committed: lenis.min.js + smooth-scroll.js (not yet wired), scripts/ (v9 import/migration), deploy/ docs (DEPLOY.md/backup.sh/nginx/verify.ps1), .well-known/assetlinks.json. audio-player.js.bak.20260614 deliberately NOT committed.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/env bash
2#
3# PrutCMS v10 — nightly backup script.
4#
5# Snapshots:
6# • SQLite database (uses .backup so it's safe while the app is running)
7# • storage/audio/ (uploaded MP3s — files outside /media for security)
8# • storage/media/ (avatars, audio covers — public files)
9# • storage/.audio-secret (HMAC secret — needed to verify old signed URLs)
10#
11# Output: a single tar.gz per run in $BACKUP_DIR, named by timestamp.
12# Rotation: keeps the last $KEEP_DAYS dumps, prunes older.
13#
14# Recommended cron:
15# 0 3 * * * /home/robin/prutcms/deploy/backup.sh >> /home/robin/prutcms/logs/backup.log 2>&1
16
17set -euo pipefail
18
19# ── Config ────────────────────────────────────────────────────────
20APP_DIR="${APP_DIR:-/home/robin/prutcms}"
21BACKUP_DIR="${BACKUP_DIR:-/home/robin/backups/prutcms}"
22KEEP_DAYS="${KEEP_DAYS:-14}"
23TS="$(date +%Y%m%d-%H%M%S)"
24
25mkdir -p "$BACKUP_DIR"
26
27# ── DB snapshot via sqlite3 .backup (consistent under WAL) ────────
28DB_FILE="$APP_DIR/storage/database.sqlite"
29DB_SNAPSHOT="$BACKUP_DIR/db-$TS.sqlite"
30if [ -f "$DB_FILE" ]; then
31 sqlite3 "$DB_FILE" ".backup '$DB_SNAPSHOT'"
32else
33 echo "WARN: $DB_FILE not found, skipping DB backup" >&2
34fi
35
36# ── Tar the snapshot + storage subdirs ────────────────────────────
37ARCHIVE="$BACKUP_DIR/prutcms-$TS.tar.gz"
38tar -czf "$ARCHIVE" \
39 -C "$BACKUP_DIR" "$(basename "$DB_SNAPSHOT")" \
40 -C "$APP_DIR/storage" \
41 $( [ -d "$APP_DIR/storage/audio" ] && echo audio ) \
42 $( [ -d "$APP_DIR/storage/media" ] && echo media ) \
43 $( [ -f "$APP_DIR/storage/.audio-secret" ] && echo .audio-secret )
44
45# Remove the loose db-XXX.sqlite (it's inside the tarball now)
46rm -f "$DB_SNAPSHOT"
47
48# ── Rotation ───────────────────────────────────────────────────────
49find "$BACKUP_DIR" -type f -name 'prutcms-*.tar.gz' -mtime "+$KEEP_DAYS" -delete
50
51SIZE="$(du -h "$ARCHIVE" | cut -f1)"
52echo "[$TS] backup OK: $ARCHIVE ($SIZE)"
Note: See TracBrowser for help on using the repository browser.