Add deployment script and documentation for production data safety

This commit is contained in:
Torsten Schulz (local)
2025-10-21 16:32:19 +02:00
parent fd135495e5
commit 2b4db04ea1
3 changed files with 201 additions and 0 deletions

72
deploy-production.sh Executable file
View File

@@ -0,0 +1,72 @@
#!/bin/bash
# Deployment Script für Harheimer TC Website
# Sichert Produktivdaten vor dem Build und stellt sie danach wieder her
echo "=== Harheimer TC Deployment ==="
echo ""
# 1. Git Pull
echo "1. Pulling latest changes from git..."
git pull
if [ $? -ne 0 ]; then
echo "ERROR: Git pull failed!"
exit 1
fi
# 2. Backup Production Data
echo ""
echo "2. Backing up production data..."
mkdir -p .backup
cp -r server/data .backup/data_backup 2>/dev/null || echo "No server/data to backup"
cp public/data/termine.csv .backup/termine.csv 2>/dev/null || echo "No termine.csv to backup"
cp public/data/mannschaften.csv .backup/mannschaften.csv 2>/dev/null || echo "No mannschaften.csv to backup"
cp public/data/spielsysteme.csv .backup/spielsysteme.csv 2>/dev/null || echo "No spielsysteme.csv to backup"
cp public/data/vereinsmeisterschaften.csv .backup/vereinsmeisterschaften.csv 2>/dev/null || echo "No vereinsmeisterschaften.csv to backup"
# 3. Install dependencies
echo ""
echo "3. Installing dependencies..."
npm install
if [ $? -ne 0 ]; then
echo "ERROR: npm install failed!"
exit 1
fi
# 4. Remove old build (but keep data!)
echo ""
echo "4. Removing old build output..."
rm -rf .output
# 5. Build
echo ""
echo "5. Building application..."
npm run build
if [ $? -ne 0 ]; then
echo "ERROR: Build failed!"
exit 1
fi
# 6. Restore Production Data
echo ""
echo "6. Restoring production data..."
cp -r .backup/data_backup/* server/data/ 2>/dev/null || echo "No data to restore"
cp .backup/termine.csv public/data/termine.csv 2>/dev/null || echo "No termine.csv to restore"
cp .backup/mannschaften.csv public/data/mannschaften.csv 2>/dev/null || echo "No mannschaften.csv to restore"
cp .backup/spielsysteme.csv public/data/spielsysteme.csv 2>/dev/null || echo "No spielsysteme.csv to restore"
cp .backup/vereinsmeisterschaften.csv public/data/vereinsmeisterschaften.csv 2>/dev/null || echo "No vereinsmeisterschaften.csv to restore"
# 7. Cleanup backup
echo ""
echo "7. Cleaning up backup..."
rm -rf .backup
# 8. Restart PM2
echo ""
echo "8. Restarting PM2..."
pm2 restart harheimertc
echo ""
echo "=== Deployment completed successfully! ==="
echo "The application is now running with the latest code and your production data preserved."