Files
krafttrainer/scripts/backup-db.sh
Christoph K. 6d7d353ea2 Add database backup script
scripts/backup-db.sh copies the remote DB via scp to ./backups/
with a timestamp. Backups older than 30 days are auto-deleted.
Backup directory is gitignored.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 20:43:58 +01:00

24 lines
748 B
Bash
Executable File

#!/usr/bin/env bash
# Erstellt ein Backup der Krafttrainer-Datenbank vom Server.
# Verwendung: ./scripts/backup-db.sh [user@host]
#
# Standard-Ziel: christoph@192.168.1.118
# Backups werden in ./backups/ gespeichert.
set -euo pipefail
REMOTE="${1:-christoph@192.168.1.118}"
REMOTE_DB="/home/christoph/fitnesspad/krafttrainer.db"
BACKUP_DIR="$(dirname "$0")/../backups"
TIMESTAMP="$(date +%Y-%m-%d_%H-%M-%S)"
BACKUP_FILE="${BACKUP_DIR}/krafttrainer_${TIMESTAMP}.db"
mkdir -p "$BACKUP_DIR"
echo "Backup von ${REMOTE}:${REMOTE_DB} ..."
scp "${REMOTE}:${REMOTE_DB}" "${BACKUP_FILE}"
echo "Gespeichert: ${BACKUP_FILE}"
# Alte Backups (älter als 30 Tage) löschen
find "$BACKUP_DIR" -name "krafttrainer_*.db" -mtime +30 -delete 2>/dev/null && true