@echo off
@if "%~0" == "%cd%\%~nx0" (set pause=@pause) else (set pause=@rem)
if not exist vars.txt (
	echo Error: 'vars.txt' not found.
	pause
	exit
)
ren vars.txt *.bat
call vars.bat
ren vars.bat *.txt
cls
prompt $N:$G
cd
REM ----------------------------------------------
rmdir /S /Q ..\game\UPDATE 2>NUL
rmdir /S /Q ..\login\UPDATE 2>NUL
@set T=%DATE%-%TIME:~0,5%
@set T=%T: =0%
@set T=%T:/=%
@set T=%T::=%
set GS=gameserver_backup-%T%.sql
set LS=loginserver_backup-%T%.sql
set CS=communityserver_backup-%T%.sql

echo.
echo Backup gameserver database to '%GS%'
@echo on
"%mysqldumpPath%" --force --default-character-set=utf8 --add-drop-table -h %gshost% -u %gsuser% --password=%gspass% %gsdb% > "%GS%"
@echo off

if "%gshost%\%gsdb%" == "%lshost%\%lsdb%" goto end_loginserver_backup
echo Backup loginserver database to '%LS%'
@echo on
"%mysqldumpPath%" --force --default-character-set=utf8 --add-drop-table -h %lshost% -u %lsuser% --password=%lspass% %lsdb% > "%LS%"
@echo off
:end_loginserver_backup

if "%gshost%\%gsdb%" == "%cbhost%\%cbdb%" goto end_communityserver_backup
echo Backup communityserver database to '%CS%'
@echo on
"%mysqldumpPath%" --force --default-character-set=utf8 --add-drop-table -h %cbhost% -u %cbuser% --password=%cbpass% %cbdb% > "%CS%"
@echo off
:end_communityserver_backup

REM ----------------------------------------------
echo.
echo Script complete.
%pause%
