source: Klonkt/deploy/backup.sh@ d2b7247

main
Last change on this file since d2b7247 was d2b7247, checked in by Robin Genis <roboburr@…>, 2 months ago

chore(branding): stale product names in comments + deploy templates -> Klonkt

Cosmetic only — comments (CSS/EJS/SQL/ecosystem.config.cjs headers) and the deploy/ doc
templates: old names (PrutCMS/PrutFolio) -> Klonkt, stale Prutter (removed DM feature) mentions
dropped, deploy/ Dutch comments translated to English. No code, identifiers, rendered strings,
package name, PWA id, real infra paths, or roboburr refs touched.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/env bash
2#
3# Klonkt — 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/klonkt/deploy/backup.sh >> /home/robin/klonkt/logs/backup.log 2>&1
16
17set -euo pipefail
18
19# ── Config ────────────────────────────────────────────────────────
20APP_DIR="${APP_DIR:-/home/robin/klonkt}"
21BACKUP_DIR="${BACKUP_DIR:-/home/robin/backups/klonkt}"
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/klonkt-$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 'klonkt-*.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.