#!/bin/bash
# Deploy PeerCortex from pre-copied files (server.js already in place via SCP)
BACKUP_DIR=/opt/peercortex-app/backups
mkdir -p $BACKUP_DIR
TS=$(date +%Y%m%d_%H%M%S)
cp /opt/peercortex-app/server.js $BACKUP_DIR/server.js.$TS
ls -t $BACKUP_DIR/server.js.* 2>/dev/null | tail -n +21 | xargs rm -f 2>/dev/null
echo "[backup] Saved server.js ($TS)"
pm2 restart peercortex
