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:
@@ -101,10 +101,17 @@ npm run backup
|
|||||||
This creates `study-app-backup_<timestamp>.zip` in the project root.
|
This creates `study-app-backup_<timestamp>.zip` in the project root.
|
||||||
|
|
||||||
**On the new machine — restore after cloning and installing:**
|
**On the new machine — restore after cloning and installing:**
|
||||||
|
|
||||||
|
Development:
|
||||||
```bash
|
```bash
|
||||||
npm run restore study-app-backup_<timestamp>.zip
|
npm run restore study-app-backup_<timestamp>.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Production (after `sudo bash deploy/install.sh` completes):
|
||||||
|
```bash
|
||||||
|
sudo bash scripts/restore-data.sh study-app-backup_<timestamp>.zip --production
|
||||||
|
```
|
||||||
|
|
||||||
See [scripts/backup-data.sh](scripts/backup-data.sh) and [scripts/restore-data.sh](scripts/restore-data.sh) for details.
|
See [scripts/backup-data.sh](scripts/backup-data.sh) and [scripts/restore-data.sh](scripts/restore-data.sh) for details.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+30
-3
@@ -1,16 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Restores user data from a backup zip created by backup-data.sh.
|
# 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
|
set -e
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
APP_DIR="$(dirname "$SCRIPT_DIR")"
|
APP_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
DATA_DIR="$APP_DIR/server/data"
|
|
||||||
BACKUP_FILE="$1"
|
BACKUP_FILE="$1"
|
||||||
|
MODE="${2:-}"
|
||||||
|
|
||||||
if [ -z "$BACKUP_FILE" ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -19,6 +24,18 @@ if [ ! -f "$BACKUP_FILE" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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"
|
mkdir -p "$DATA_DIR"
|
||||||
|
|
||||||
# Warn if a database already exists
|
# Warn if a database already exists
|
||||||
@@ -35,6 +52,16 @@ fi
|
|||||||
|
|
||||||
unzip -o "$BACKUP_FILE" -d "$DATA_DIR"
|
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 ""
|
||||||
echo "Restore complete. Database is at: $DATA_DIR/projects.db"
|
echo "Restore complete. Database is at: $DATA_DIR/projects.db"
|
||||||
|
if [ "$MODE" = "--production" ]; then
|
||||||
|
echo "Check service status: systemctl status study-app"
|
||||||
|
else
|
||||||
echo "You can now start the app normally."
|
echo "You can now start the app normally."
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user