From 085043c9914d80efd1650ea5d987b1e44278b697 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Mon, 13 Jul 2026 10:26:32 -0400 Subject: [PATCH] Fix production restore: add --production flag to restore into /opt/study-app and restart service Co-Authored-By: Claude Sonnet 4.6 --- README.md | 7 +++++++ scripts/restore-data.sh | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad9e66e..420eba0 100644 --- a/README.md +++ b/README.md @@ -101,10 +101,17 @@ npm run backup This creates `study-app-backup_.zip` in the project root. **On the new machine — restore after cloning and installing:** + +Development: ```bash npm run restore study-app-backup_.zip ``` +Production (after `sudo bash deploy/install.sh` completes): +```bash +sudo bash scripts/restore-data.sh study-app-backup_.zip --production +``` + See [scripts/backup-data.sh](scripts/backup-data.sh) and [scripts/restore-data.sh](scripts/restore-data.sh) for details. --- diff --git a/scripts/restore-data.sh b/scripts/restore-data.sh index 6d624b0..d4e30c8 100755 --- a/scripts/restore-data.sh +++ b/scripts/restore-data.sh @@ -1,16 +1,21 @@ #!/bin/bash # Restores user data from a backup zip created by backup-data.sh. -# Usage: scripts/restore-data.sh +# +# Development usage: +# npm run restore +# +# Production usage (restores into the running service directory): +# sudo bash scripts/restore-data.sh --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 " + echo "Usage: scripts/restore-data.sh [--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