the files
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
@echo off
|
||||
setlocal EnableDelayedExpansion
|
||||
REM ============================================================
|
||||
REM Campus 2025 server deploy -- WITH DB WIPE
|
||||
REM -----------------------------------------------------------
|
||||
REM Same upload+install flow as DeployCampusServer.bat, but the
|
||||
REM live /opt/campus/Data/DBs/ folder on the VPS is BACKED UP
|
||||
REM and then REMOVED before install.sh runs, so the DBs shipped
|
||||
REM in the tarball (i.e. whatever's in your local
|
||||
REM Server\2025-RecRoom-Server-E12354-main\Data\DBs\
|
||||
REM ) end up as the new live DBs on the VPS.
|
||||
REM
|
||||
REM Backups live at /root/campus-dbs-backup-YYYYMMDD_HHMMSS/
|
||||
REM on the VPS -- pull one down with pscp if you need to roll
|
||||
REM back, or `rm -rf` them yourself once you're happy.
|
||||
REM
|
||||
REM Requires:
|
||||
REM - campus-deploy.tar.gz next to this .bat (run PackageServer.ps1)
|
||||
REM - password.txt next to this .bat with the VPS root password
|
||||
REM - PuTTY tools (pscp + plink) on PATH
|
||||
REM ============================================================
|
||||
|
||||
cd /d "%~dp0"
|
||||
|
||||
set HOST=50.114.179.17
|
||||
set DOMAIN=gameauth.ddns.net
|
||||
set USER=root
|
||||
set PKG=campus-deploy.tar.gz
|
||||
set PWFILE=password.txt
|
||||
|
||||
echo.
|
||||
echo ===========================================
|
||||
echo Campus 2025 - DEPLOY + WIPE DBs
|
||||
echo target : %USER%@%HOST%
|
||||
echo domain : https://%DOMAIN%
|
||||
echo ===========================================
|
||||
echo.
|
||||
echo !!! DESTRUCTIVE - PLEASE READ !!!
|
||||
echo.
|
||||
echo This will REPLACE every LiteDB file under
|
||||
echo /opt/campus/Data/DBs/
|
||||
echo on the VPS with the copies inside your local
|
||||
echo Server\2025-RecRoom-Server-E12354-main\Data\DBs\
|
||||
echo.
|
||||
echo Affected files (all LiteDB collections):
|
||||
echo Players.db PlayersFriends.db
|
||||
echo Rooms.db Chat.db Events.db
|
||||
echo Heartbeats.db Leaderboard.db Images.db
|
||||
echo Settings.db (and every *-log.db)
|
||||
echo.
|
||||
echo Existing live DBs are copied to
|
||||
echo /root/campus-dbs-backup-YYYYMMDD_HHMMSS/
|
||||
echo before deletion, so this is reversible if you
|
||||
echo act fast, but any new writes AFTER the deploy
|
||||
echo land in the new DBs and cannot be merged back.
|
||||
echo.
|
||||
set /p CONFIRM=" Type YES (all caps) to continue, anything else aborts: "
|
||||
if not "%CONFIRM%"=="YES" (
|
||||
echo.
|
||||
echo aborted, nothing was sent.
|
||||
goto :end
|
||||
)
|
||||
|
||||
REM --- checks -------------------------------------------------
|
||||
if not exist "%PWFILE%" (
|
||||
echo [X] %PWFILE% not found next to this .bat.
|
||||
goto :fail
|
||||
)
|
||||
if not exist "%PKG%" (
|
||||
echo [X] %PKG% not found. Run PackageServer.ps1 first.
|
||||
goto :fail
|
||||
)
|
||||
where pscp >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [X] PuTTY tools not found ^(pscp/plink^).
|
||||
echo winget install PuTTY.PuTTY ^(then reopen this window^)
|
||||
goto :fail
|
||||
)
|
||||
|
||||
REM --- read the password (first line only, never echoed) ------
|
||||
set PW=
|
||||
for /f "usebackq delims=" %%p in ("%PWFILE%") do (
|
||||
if not defined PW set "PW=%%p"
|
||||
)
|
||||
if not defined PW (
|
||||
echo [X] %PWFILE% is empty.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [1/3] Uploading %PKG% ...
|
||||
echo ^(~49 MB - pscp shows a live progress bar below^)
|
||||
echo.
|
||||
echo y | pscp -pw "!PW!" "%PKG%" %USER%@%HOST%:/root/
|
||||
if errorlevel 1 (
|
||||
echo [X] Upload failed - wrong password, or host unreachable.
|
||||
goto :fail
|
||||
)
|
||||
echo upload complete.
|
||||
echo.
|
||||
|
||||
echo [2/3] Backing up live DBs, wiping them, then installing ...
|
||||
echo Backup path shows below as 'backed up existing DBs -^> ...'
|
||||
echo Then install.sh runs normally; because the DB dir is empty
|
||||
echo after the wipe, the tarball's DBs become the new live DBs.
|
||||
echo.
|
||||
REM One long plink line - CMD parses this whole quoted string as a single arg
|
||||
REM to plink. Inside, we run the wipe+backup, then hand off to install.sh
|
||||
REM exactly like the normal deploy path.
|
||||
echo y | plink -ssh -pw "!PW!" %USER%@%HOST% "cd /root && rm -rf campus-deploy && mkdir campus-deploy && echo ' extracting archive ...' && tar -xzf %PKG% -C campus-deploy && TS=$(date +%%Y%%m%%d_%%H%%M%%S) && BACKUP=/root/campus-dbs-backup-$TS && if [ -d /opt/campus/Data/DBs ]; then mkdir -p $BACKUP && cp -a /opt/campus/Data/DBs/. $BACKUP/ 2>/dev/null || true; echo ' backed up existing DBs -> '$BACKUP; systemctl stop campus 2>/dev/null || true; sleep 2; rm -rf /opt/campus/Data/DBs; echo ' wiped /opt/campus/Data/DBs'; fi && cd campus-deploy && chmod +x install.sh && ./install.sh"
|
||||
if errorlevel 1 (
|
||||
echo [X] Install failed - see the output above.
|
||||
echo Live DBs were backed up to /root/campus-dbs-backup-YYYYMMDD_HHMMSS/
|
||||
echo on the VPS before the wipe, so you can restore them.
|
||||
goto :fail
|
||||
)
|
||||
echo.
|
||||
|
||||
echo [3/3] Smoke test ...
|
||||
timeout /t 3 /nobreak >nul
|
||||
curl -sk --ssl-no-revoke -o nul -w " https://%DOMAIN%/ -> HTTP %%{http_code}%%\n" --max-time 10 https://%DOMAIN%/
|
||||
echo.
|
||||
|
||||
echo ===========================================
|
||||
echo DONE!
|
||||
echo.
|
||||
echo Live DBs on the VPS have been replaced with
|
||||
echo the local copies in this repo.
|
||||
echo.
|
||||
echo Rollback (from a VPS shell):
|
||||
echo systemctl stop campus
|
||||
echo rm -rf /opt/campus/Data/DBs
|
||||
echo cp -a /root/campus-dbs-backup-YYYYMMDD_HHMMSS /opt/campus/Data/DBs
|
||||
echo systemctl start campus
|
||||
echo.
|
||||
echo Clean up old backups when done:
|
||||
echo ls -1dt /root/campus-dbs-backup-*
|
||||
echo rm -rf /root/campus-dbs-backup-YYYYMMDD_HHMMSS
|
||||
echo.
|
||||
echo Server IP: %HOST%
|
||||
echo Domain: https://%DOMAIN%
|
||||
echo ===========================================
|
||||
echo.
|
||||
goto :end
|
||||
|
||||
:fail
|
||||
echo.
|
||||
echo Deploy aborted.
|
||||
echo.
|
||||
|
||||
:end
|
||||
set PW=
|
||||
pause
|
||||
Reference in New Issue
Block a user