Fix production restore: add --production flag to restore into /opt/study-app and restart service

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmert
2026-07-13 10:26:32 -04:00
parent 092a81718d
commit 085043c991
2 changed files with 38 additions and 4 deletions
+31 -4
View File
@@ -1,16 +1,21 @@
#!/bin/bash
# Restores user data from a backup zip created by backup-data.sh.
# Usage: scripts/restore-data.sh <path-to-backup-file>
#
# Development usage:
# npm run restore <path-to-backup-file>
#
# Production usage (restores into the running service directory):
# sudo bash scripts/restore-data.sh <path-to-backup-file> --production
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="$(dirname "$SCRIPT_DIR")"
DATA_DIR="$APP_DIR/server/data"
BACKUP_FILE="$1"
MODE="${2:-}"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: scripts/restore-data.sh <path-to-backup-file>"
echo "Usage: scripts/restore-data.sh <path-to-backup-file> [--production]"
exit 1
fi
@@ -19,6 +24,18 @@ if [ ! -f "$BACKUP_FILE" ]; then
exit 1
fi
if [ "$MODE" = "--production" ]; then
DATA_DIR="/opt/study-app/server/data"
SERVICE_USER="study-app"
if [ "$EUID" -ne 0 ]; then
echo "ERROR: Production restore must be run as root (sudo)."
exit 1
fi
else
DATA_DIR="$APP_DIR/server/data"
SERVICE_USER=""
fi
mkdir -p "$DATA_DIR"
# Warn if a database already exists
@@ -35,6 +52,16 @@ fi
unzip -o "$BACKUP_FILE" -d "$DATA_DIR"
if [ -n "$SERVICE_USER" ]; then
chown "$SERVICE_USER":"$SERVICE_USER" "$DATA_DIR/projects.db"
echo "Restarting study-app service..."
systemctl restart study-app
fi
echo ""
echo "Restore complete. Database is at: $DATA_DIR/projects.db"
echo "You can now start the app normally."
if [ "$MODE" = "--production" ]; then
echo "Check service status: systemctl status study-app"
else
echo "You can now start the app normally."
fi