@echo off
cls
echo *********************************************
echo *          S V R T S P O S . F D B          *
echo *  Please make sure database is not in use  *
echo *                                           *
echo *        Press CTRL + C to abort fix        *
echo *                    or                     *
echo *          Click [X] to abort fix           *
echo *                                           *
echo *        After 10 seconds will start        *
echo *********************************************

echo WScript.Sleep(10000) >"%temp%\sleep.vbs"
cscript "%temp%\sleep.vbs"

Set myDir=D:\QasDev\QubeXE\FrontPos\Db
Set mytime=000000
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=5-7 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set mytime=%%i%%j%%k

echo ***************************************************
echo *    This Process will Backup the SvrTsPos.fdb       
echo *  C:\QubeData\Backup\SvrTsPos-%mydate%_%mytime%.7z
echo ***************************************************
md C:\QubeData\Backup
rem eg.Copy %myDir%\SvrTsPos.fdb C:\QubeData\Backup\SvrTsPos-%mydate%%mytime%.fdb.copy /v /y
rem eg.7z x C:\QubeData\Backup\____.7z
%myDir%\7z a C:\QubeData\Backup\SvrTsPos-%mydate%_%mytime%.7z %myDir%\SvrTsPos.fdb
echo ----- Backup Completed
echo ----- After 5 seconds will continue
echo WScript.Sleep(5000) >"%temp%\sleep.vbs"
cscript "%temp%\sleep.vbs"

echo *************************************************************
echo *  This Process will begin the Mending database Operations  *
echo *************************************************************
%myDir%\gfix -m -i %myDir%\SvrTsPos.fdb -user SYSDBA -password masterkey
echo ----- Mending Completed
echo ----- After 5 seconds will continue
echo WScript.Sleep(5000) >"%temp%\sleep.vbs"
cscript "%temp%\sleep.vbs"

echo *************************************************************************
echo *  This Process will begin the Backup and Trimming database Operations  *
echo *************************************************************************
%myDir%\gbak -g -b -z -v %myDir%\SvrTsPos.fdb %temp%\SvrTsPos.fdb.backup -user SYSDBA -password masterkey
echo ----- Backup and Trimming completed
echo ----- After 5 seconds will continue
echo WScript.Sleep(5000) >"%temp%\sleep.vbs"
cscript "%temp%\sleep.vbs"

echo **********************************************************************
echo *  This Process will begin the Restore the good database Operations  *
echo **********************************************************************
%myDir%\gbak -c -v -z -rep %temp%\SvrTsPos.fdb.backup %myDir%\SvrTsPos.fdb -user SYSDBA -password masterkey
echo ----- Restore Completed

pause


