@echo off
cls
echo *********************************************
echo *          P O S _ Q F N B . 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 15 seconds will start        *
echo *********************************************

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

Set myDir=C:\QasDev\QubeXE\BackEnd\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 Pos_QFnb.fdb       
echo *  C:\QubeData\Backup\Pos_QFnb-%mydate%_%mytime%.7z  
echo ***************************************************
md C:\QubeData\Backup
rem Copy %myDir%\Pos_QFnb.fdb C:\QubeData\Backup\Pos_QFnb-%mydate%%mytime%.fdb.copy /v /y
rem eg.7z x C:\QubeData\Backup\____.7z
%myDir%\7z a C:\QubeData\Backup\Pos_QFnb-%mydate%_%mytime%.7z %myDir%\Pos_QFnb.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%\Pos_QFnb.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%\Pos_QFnb.fdb %temp%\Pos_QFnb.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 good database Operations  *
echo ******************************************************************
%myDir%\gbak -c -v -z -rep %temp%\Pos_QFnb.fdb.backup %myDir%\Pos_QFnb.fdb -user SYSDBA -password masterkey
echo ----- Restore Completed

pause