Firebird Automatic Database Restore on to Backup Server

I maintain a server running the Firebird database that backs-up the database on a daily basis. I also have a server that can be used as a backup in case the main server fails. I wanted to make it so the database is automatically restored on to the backup server every day so I always have the previous days’ data on that server ready to go.

This is specifically for Quantum Control software (which uses Firebird) but I hope it might be helpful to other users of Firebird as well.

This is mainly for users who have some knowledge of database backup and windows batch scripting since the script will require modification to fit your circumstances.

I have a batch file (cp_bak.bat) located in a folder on the desktop names “mainserver QC bak”.

If you use this script you will want to modify several things. First off update all of the locations and server names. Here I use “mainserver” for my database server that clients are using day to day.
For the “net use” command you will want to use appropriate credentials to access the backup file (which I back up with 7z).

@echo off

cd "\Documents and Settings\Administrator\Desktop\mainserver QC bak"

echo Accessing share (net use)...
net use \\mainserver\Quantum mikepassword /USER:mike
echo Copying QC.7z from mainserver...
copy \\mainserver\Quantum\bak\QC.7z "C:\Documents and Settings\Administrator\Desktop\mainserver QC bak\"

echo Removing old extract (Will print error if it does not exist)...
del QUANTUM.FDB.bak
echo Extracting...
C:\Admin\Bin\7za.exe e QC.7z

echo Stopping firebird
sc stop FirebirdGuardianDefaultInstance
timeout 4
echo Overwriting database with backup...
move QUANTUM.FDB.bak C:\Quantum\Database\QUANTUM.FDB
echo Starting firebird
sc start FirebirdGuardianDefaultInstance
timeout 3
echo "Unlocking database..."
"c:\quantum\firebird\bin\gfix.exe" -online "127.0.0.1:c:\quantum\database\quantum.fdb" -user sysdba -pass masterkey 2> "c:\quantum\database\error.txt"

timeout 1

echo "Setting correct security database, turning off maintenance broadcast"
cd "\Documents and Settings\Administrator\Desktop\mainserver QC bak"
"c:\quantum\firebird\bin\isql.exe" "127.0.0.1:c:\quantum\database\quantum.fdb" -i security_update.fbsql -u sysdba -p masterkey 

echo Done!

This script references a SQL file in the same directory named security_update.fbsql

update quantum set locked='F';

update quantum set serverdb='192.168.2.3:c:\quantum\firebird\security.fdb', broadcast='F';

Important things to not in this is that this is the security database on the backup server with the backup IP address. It also disables the database maintenance broadcast message (in Quantum Control).

Leave a Reply

Your email address will not be published. Required fields are marked *

To see if you are a human *