Subject | Re: [firebird-support] Using a batch file to run a nightly bakup using GBAK |
---|---|
Author | Carlos Tré |
Post date | 2010-12-20T20:14:04Z |
Hi Mike,
I use a batch that's been working flawlessly for a long time. Feel free
to write directly to me if you want discuss any batch file specifics :-)
(comments in my mother language, sorry, no time to translate now)
@echo off
REM
REM
============================================================================
REM efetua backup dos bancos de dados
REM
============================================================================
REM
REM Diretórios de Trabalho
REM
SET BKP_DIR=E:\BaseSysFolder\Bkp
SET FTP_DIR=%BKP_DIR%\FTP
SET RST_DIR=E:\BaseSysFolder\Rst
SET FBB_DIR=%ProgramFiles%\Firebird\Firebird_1_5\bin
SET CLT_DIR=C:\MyToolsFolder\CL
SET SCP_DIR=C:\MyToolsFolder\WinSCP
SET BAT_DIR=E:\BaseSysFolder\Bat
REM
REM Executáveis Diversos
REM
SET GBAK_EXE="%FBB_DIR%\gbak.exe"
SET GREP_EXE=%CLT_DIR%\grep.exe
REM
REM Diferenciadores por data e hora
REM
FOR /f "tokens=2-4 delims=/ " %%a IN ('DATE /t') DO (SET BKP_DATE=%%c%%b%%a)
FOR /f "tokens=1-2 delims=: " %%a IN ('TIME /t') DO (SET
BKP_IDNT=%BKP_DATE%_%%a%%b)
REM
REM
REM Arquivo de Log e Relatório
REM
SET JOB_LOG=%BKP_DIR%\MySystemName_BackupJob_%BKP_IDNT%.LOG
SET JOB_REP=%BKP_DIR%\MySystemName_JobReport_%BKP_IDNT%.TXT
SET ERR_REP=%BKP_DIR%\MySystemName_ErrorReport_%BKP_IDNT%.TXT
REM
REM Arquivos da Base de Dados IWH
REM
SET SYS_BKP_GBK=%BKP_DIR%\MySystemName_Data_%BKP_IDNT%.FBK
SET SYS_BKP_ZIP=%BKP_DIR%\MySystemName_Data_%BKP_IDNT%.ZIP
SET SYS_BKP_GDB=localhost:DAT_Alias
SET SYS_BKP_LOG=%BKP_DIR%\SYSBackup_%BKP_IDNT%.LOG
SET SYS_RST_GDB=localhost:RST_Alias
SET SYS_RST_LOG=%RST_DIR%\SYSRestore_%BKP_IDNT%.LOG
SET SYS_ZIP_LOG=%BKP_DIR%\MySystemName_ZIP_%BKP_IDNT%.LOG
REM
REM
============================================================================
REM Prepara Arquivo de Relatório
REM
============================================================================
REM
if exist %JOB_LOG% del %JOB_LOG%
echo %DATE% %TIME% > %JOB_LOG%
REM
REM
============================================================================
REM Backup SYS
REM
============================================================================
REM
REM apaga log anterior e faz o backup do arquivo de dados
REM
if exist %SYS_BKP_LOG% del %SYS_BKP_LOG%
%GBAK_EXE% -b -t -v -user XXXXXXX -pas xxxxxx %SYS_BKP_GDB%
%SYS_BKP_GBK% -y %SYS_BKP_LOG%
%GREP_EXE% -i "committing, and finishing" %SYS_BKP_LOG%
if ERRORLEVEL 1 goto SYS_BkpErr
echo SYS_Backup Terminou Ok >> %JOB_LOG%
REM
REM verifica se cópia pode ser restaurada com sucesso
REM
if exist %SYS_RST_LOG% del %SYS_RST_LOG%
%GBAK_EXE% -c -v -r -p 8192 -user XXXXXXX -pas xxxxxx %SYS_BKP_GBK%
%SYS_RST_GDB% -y %SYS_RST_LOG%
%GREP_EXE% -i "finishing, closing, and going home" %SYS_RST_LOG%
if ERRORLEVEL 1 goto SYS_RstErr
echo SYS_Restore Terminou Ok >> %JOB_LOG%
GOTO BkpJobEnd
:SYS_BkpErr
echo Falha em SYS_Backup >> %JOB_LOG%
echo Falha em SYS_Backup >> %ERR_REP%
GOTO BkpJobEnd
:SYS_RstErr
echo Falha em SYS_Restore >> %JOB_LOG%
echo Falha em SYS_Restore >> %ERR_REP%
GOTO BkpJobEnd
:BkpJobEnd
echo %DATE% %TIME% >> %JOB_LOG%
I use a batch that's been working flawlessly for a long time. Feel free
to write directly to me if you want discuss any batch file specifics :-)
(comments in my mother language, sorry, no time to translate now)
@echo off
REM
REM
============================================================================
REM efetua backup dos bancos de dados
REM
============================================================================
REM
REM Diretórios de Trabalho
REM
SET BKP_DIR=E:\BaseSysFolder\Bkp
SET FTP_DIR=%BKP_DIR%\FTP
SET RST_DIR=E:\BaseSysFolder\Rst
SET FBB_DIR=%ProgramFiles%\Firebird\Firebird_1_5\bin
SET CLT_DIR=C:\MyToolsFolder\CL
SET SCP_DIR=C:\MyToolsFolder\WinSCP
SET BAT_DIR=E:\BaseSysFolder\Bat
REM
REM Executáveis Diversos
REM
SET GBAK_EXE="%FBB_DIR%\gbak.exe"
SET GREP_EXE=%CLT_DIR%\grep.exe
REM
REM Diferenciadores por data e hora
REM
FOR /f "tokens=2-4 delims=/ " %%a IN ('DATE /t') DO (SET BKP_DATE=%%c%%b%%a)
FOR /f "tokens=1-2 delims=: " %%a IN ('TIME /t') DO (SET
BKP_IDNT=%BKP_DATE%_%%a%%b)
REM
REM
REM Arquivo de Log e Relatório
REM
SET JOB_LOG=%BKP_DIR%\MySystemName_BackupJob_%BKP_IDNT%.LOG
SET JOB_REP=%BKP_DIR%\MySystemName_JobReport_%BKP_IDNT%.TXT
SET ERR_REP=%BKP_DIR%\MySystemName_ErrorReport_%BKP_IDNT%.TXT
REM
REM Arquivos da Base de Dados IWH
REM
SET SYS_BKP_GBK=%BKP_DIR%\MySystemName_Data_%BKP_IDNT%.FBK
SET SYS_BKP_ZIP=%BKP_DIR%\MySystemName_Data_%BKP_IDNT%.ZIP
SET SYS_BKP_GDB=localhost:DAT_Alias
SET SYS_BKP_LOG=%BKP_DIR%\SYSBackup_%BKP_IDNT%.LOG
SET SYS_RST_GDB=localhost:RST_Alias
SET SYS_RST_LOG=%RST_DIR%\SYSRestore_%BKP_IDNT%.LOG
SET SYS_ZIP_LOG=%BKP_DIR%\MySystemName_ZIP_%BKP_IDNT%.LOG
REM
REM
============================================================================
REM Prepara Arquivo de Relatório
REM
============================================================================
REM
if exist %JOB_LOG% del %JOB_LOG%
echo %DATE% %TIME% > %JOB_LOG%
REM
REM
============================================================================
REM Backup SYS
REM
============================================================================
REM
REM apaga log anterior e faz o backup do arquivo de dados
REM
if exist %SYS_BKP_LOG% del %SYS_BKP_LOG%
%GBAK_EXE% -b -t -v -user XXXXXXX -pas xxxxxx %SYS_BKP_GDB%
%SYS_BKP_GBK% -y %SYS_BKP_LOG%
%GREP_EXE% -i "committing, and finishing" %SYS_BKP_LOG%
if ERRORLEVEL 1 goto SYS_BkpErr
echo SYS_Backup Terminou Ok >> %JOB_LOG%
REM
REM verifica se cópia pode ser restaurada com sucesso
REM
if exist %SYS_RST_LOG% del %SYS_RST_LOG%
%GBAK_EXE% -c -v -r -p 8192 -user XXXXXXX -pas xxxxxx %SYS_BKP_GBK%
%SYS_RST_GDB% -y %SYS_RST_LOG%
%GREP_EXE% -i "finishing, closing, and going home" %SYS_RST_LOG%
if ERRORLEVEL 1 goto SYS_RstErr
echo SYS_Restore Terminou Ok >> %JOB_LOG%
GOTO BkpJobEnd
:SYS_BkpErr
echo Falha em SYS_Backup >> %JOB_LOG%
echo Falha em SYS_Backup >> %ERR_REP%
GOTO BkpJobEnd
:SYS_RstErr
echo Falha em SYS_Restore >> %JOB_LOG%
echo Falha em SYS_Restore >> %ERR_REP%
GOTO BkpJobEnd
:BkpJobEnd
echo %DATE% %TIME% >> %JOB_LOG%
On 20/12/2010 09:22, SoftTech wrote:
> Greetings All,
>
> Firebird 1.5 (Still)
>
> I have a batch file that will be called by the Windows Task Scheduler that
> would automatically backup the database each night.
>
> This will be run as a task directly on the Windows File Server.
>
> The batch file contains the following:
>
> FOR /F "tokens=1-5 delims=/, " %%i in ('date/t') DO SET MMDDYYYY=%%j%%k%%l
> cd C:\Program files\Firebird\Firebird_1_5\Bin
>
> gbak -v -t -user SYSDBA -password xxxxxxxx
> FS1:D:\Sys\Frontline\Coll\Database\COLL.FDB
> D:\Sys\Frontline\Coll\Database\CollDaily%MMDDYYYY%-1.bak 2000M
> D:\Sys\Frontline\Coll\Database\CollDaily%MMDDYYYY%-2.bak 2000M
> D:\Sys\Frontline\Coll\Database\CollDaily%MMDDYYYY%-3.bak
>
> Note I replaced our actual password with xxxxxxxx above...
>
> Can anyone tell me why this batch file does not work?
>
> Does anyone have a working example if this is not correct?
>
> Thanks,
> Mike
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>
>