FirebirdSQL/問答篇/批次檔執行備份修復

出自VFP Wiki

(修訂版本間差異)
跳轉到: 導航, 搜尋
(gsa)
(revert)
第1行: 第1行:
-
[http://www.bjicp.com ICP代办]
+
=== Firebird自動化設定 ===
-
[http://www.bjicp.com ICP]
+
-
[http://www.bjicp.com ICP办理]
+
-
[http://www.bjicp.com ICP证]
+
-
[http://www.bjicp.com 北京ICP]
+
-
[http://www.bjicp.com ICP经营许可证]
+
-
[http://www.bjicp.com 申请ICP经营许可证]
+
-
http://www.bjicp.com/images/braintemp_1.jpg{nid GFY}
+
 +
<code>
 +
rem @echo off
 +
rem Batch file for safe shutting down and restarting IB55
 +
rem This Batch will run on Win-NT, not on Win-9x
 +
C:
 +
CD "\Program Files\Interbase Corp\Interbase\Bin"
 +
SET BATLOGFILE=%1
 +
IF "%BATLOGFILE%" == "" SET BATLOGFILE=d:\newua\jobs\nightly.LOG
 +
echo ------------------------------------------------- >> %BATLOGFILE%
 +
Date /T >> %BATLOGFILE%
 +
Time /T >> %BATLOGFILE%
 +
rem ========= Step 1: shutdown database =========
 +
echo Try Shutdown Database... >> %BATLOGFILE%
 +
gfix -shut -attach 30 d:\newua\ua.gdb -user SYSDBA -pass masterkey 2> errout.tmp
 +
echo 1> nul 2> empty.tmp
 +
echo N 1> N_CR.tmp
 +
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
 +
if errorlevel 1 GOTO NOT_SHUT
 +
echo Shutdown ua ok >> %BATLOGFILE%
-
[http://www.bjicp.net ICP代办]
+
gfix -shut -attach 30 d:\newua\train.gdb -user SYSDBA -pass masterkey 2> errout.tmp
-
[http://www.bjicp.net ICP]
+
echo 1> nul 2> empty.tmp
-
[http://www.bjicp.net ICP办理]
+
echo N 1> N_CR.tmp
-
[http://www.bjicp.net ICP证]
+
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
-
[http://www.bjicp.net 北京ICP]
+
if errorlevel 1 GOTO NOT_SHUT_TRAIN
-
[http://www.bjicp.net ICP经营许可证]
+
echo Shutdown train ok >> %BATLOGFILE%
-
[http://www.bjicp.net 申请ICP经营许可证]
+
-
http://www.bjicp.net/images/logo.jpg {nid GFY}
+
-
[http://www.bjicp.org ICP代办]
+
rem ========= Step 2: stop InterbaseServer =========
-
[http://www.bjicp.org ICP]
+
echo Try stop InterbaseServer... >> %BATLOGFILE%
-
[http://www.bjicp.org ICP办理]
+
NET STOP InterbaseServer 1> nul 2>> %BATLOGFILE%
-
[http://www.bjicp.org ICP证]
+
IF errorlevel 1 GOTO NOT_STOPPED
-
[http://www.bjicp.org 北京ICP]
+
echo stop InterbaseServer ok >> %BATLOGFILE%
-
[http://www.bjicp.org ICP经营许可证]
+
 
-
[http://www.bjicp.org 申请ICP经营许可证]
+
rem ========= Step 3: (re)start InterbaseGuardian =========
-
http://www.bjicp.org/image/s2.gif{nid GFY}
+
echo Try start InterbaseGuardian... >> %BATLOGFILE%
 +
NET START InterbaseGuardian 1> nul 2>> %BATLOGFILE%
 +
IF errorlevel 1 GOTO NOT_STARTED
 +
echo start InterbaseGuardian ok >> %BATLOGFILE%
 +
 
 +
 
 +
rem ========= Step 4: backup database =========
 +
echo backup Database... >> %BATLOGFILE%
 +
gbak -B -t -user SYSDBA -pass masterkey  d:\newua\ua.gdb d:\newua\ua.bkp 2> errout.tmp
 +
echo 1> nul 2> empty.tmp
 +
echo N 1> N_CR.tmp
 +
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
 +
if errorlevel 1 GOTO NOT_BACKEDUP
 +
echo backup ua ok >> %BATLOGFILE%
 +
 
 +
rem ========= Step 5: restore database =========
 +
echo restore Database... >> %BATLOGFILE%
 +
gbak -R -user SYSDBA -pass masterkey  -c -p 8192 d:\newua\ua.bkp d:\newua\ua.gdb 2> errout.tmp
 +
echo 1> nul 2> empty.tmp
 +
echo N 1> N_CR.tmp
 +
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
 +
if errorlevel 1 GOTO NOT_RESTORED
 +
echo restore train ok >> %BATLOGFILE%
 +
 
 +
 
 +
rem ========= Step 6: bring database online =========
 +
echo Try bring database online... >> %BATLOGFILE%
 +
gfix -online d:\newua\ua.gdb -user SYSDBA -pass masterkey 2> errout.tmp
 +
echo 1> nul 2> empty.tmp
 +
echo N 1> N_CR.tmp
 +
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
 +
if errorlevel 1 GOTO NOT_ONLINE
 +
echo Online ua again. Finished. >> %BATLOGFILE%
 +
 
 +
gfix -online d:\newua\train.gdb -user SYSDBA -pass masterkey 2> errout.tmp
 +
echo 1> nul 2> empty.tmp
 +
echo N 1> N_CR.tmp
 +
comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp
 +
if errorlevel 1 GOTO NOT_ONLINE_TRAIN
 +
echo Online train again. Finished. >> %BATLOGFILE%
 +
 
 +
GOTO END_BATCH
 +
 
 +
:NOT_SHUT
 +
type errout.tmp >> %BATLOGFILE%
 +
echo Shutdown ua failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_SHUT_TRAIN
 +
type errout.tmp >> %BATLOGFILE%
 +
echo Shutdown train failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_STOPPED
 +
echo Stop InterbaseServer failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_STARTED
 +
echo Start InterbaseGuardian failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_BACKEDUP
 +
type errout.tmp >> %BATLOGFILE%
 +
echo Backup failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_RESTORED
 +
echo restore failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_ONLINE
 +
type errout.tmp >> %BATLOGFILE%
 +
echo Bringing ua database online failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:NOT_ONLINE_TRAIN
 +
type errout.tmp >> %BATLOGFILE%
 +
echo Bringing train database online failed! >> %BATLOGFILE%
 +
GOTO END_BATCH
 +
 
 +
:END_BATCH
 +
del *.tmp
 +
</code>

在2005年4月3日 (日) 08:11所做的修訂版本

Firebird自動化設定

rem @echo off rem Batch file for safe shutting down and restarting IB55 rem This Batch will run on Win-NT, not on Win-9x C: CD "\Program Files\Interbase Corp\Interbase\Bin" SET BATLOGFILE=%1 IF "%BATLOGFILE%" == "" SET BATLOGFILE=d:\newua\jobs\nightly.LOG echo ------------------------------------------------- >> %BATLOGFILE% Date /T >> %BATLOGFILE% Time /T >> %BATLOGFILE% rem ========= Step 1: shutdown database ========= echo Try Shutdown Database... >> %BATLOGFILE% gfix -shut -attach 30 d:\newua\ua.gdb -user SYSDBA -pass masterkey 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_SHUT echo Shutdown ua ok >> %BATLOGFILE%

gfix -shut -attach 30 d:\newua\train.gdb -user SYSDBA -pass masterkey 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_SHUT_TRAIN echo Shutdown train ok >> %BATLOGFILE%

rem ========= Step 2: stop InterbaseServer ========= echo Try stop InterbaseServer... >> %BATLOGFILE% NET STOP InterbaseServer 1> nul 2>> %BATLOGFILE% IF errorlevel 1 GOTO NOT_STOPPED echo stop InterbaseServer ok >> %BATLOGFILE%

rem ========= Step 3: (re)start InterbaseGuardian ========= echo Try start InterbaseGuardian... >> %BATLOGFILE% NET START InterbaseGuardian 1> nul 2>> %BATLOGFILE% IF errorlevel 1 GOTO NOT_STARTED echo start InterbaseGuardian ok >> %BATLOGFILE%


rem ========= Step 4: backup database ========= echo backup Database... >> %BATLOGFILE% gbak -B -t -user SYSDBA -pass masterkey d:\newua\ua.gdb d:\newua\ua.bkp 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_BACKEDUP echo backup ua ok >> %BATLOGFILE%

rem ========= Step 5: restore database ========= echo restore Database... >> %BATLOGFILE% gbak -R -user SYSDBA -pass masterkey -c -p 8192 d:\newua\ua.bkp d:\newua\ua.gdb 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_RESTORED echo restore train ok >> %BATLOGFILE%


rem ========= Step 6: bring database online ========= echo Try bring database online... >> %BATLOGFILE% gfix -online d:\newua\ua.gdb -user SYSDBA -pass masterkey 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_ONLINE echo Online ua again. Finished. >> %BATLOGFILE%

gfix -online d:\newua\train.gdb -user SYSDBA -pass masterkey 2> errout.tmp echo 1> nul 2> empty.tmp echo N 1> N_CR.tmp comp errout.tmp empty.tmp 1> nul 2> nul < N_CR.tmp if errorlevel 1 GOTO NOT_ONLINE_TRAIN echo Online train again. Finished. >> %BATLOGFILE%

GOTO END_BATCH

NOT_SHUT

type errout.tmp >> %BATLOGFILE% echo Shutdown ua failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_SHUT_TRAIN

type errout.tmp >> %BATLOGFILE% echo Shutdown train failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_STOPPED

echo Stop InterbaseServer failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_STARTED

echo Start InterbaseGuardian failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_BACKEDUP

type errout.tmp >> %BATLOGFILE% echo Backup failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_RESTORED

echo restore failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_ONLINE

type errout.tmp >> %BATLOGFILE% echo Bringing ua database online failed! >> %BATLOGFILE% GOTO END_BATCH

NOT_ONLINE_TRAIN

type errout.tmp >> %BATLOGFILE% echo Bringing train database online failed! >> %BATLOGFILE% GOTO END_BATCH

END_BATCH

del *.tmp