Hotcopy | Hackcopy Firebird
New problem within the Firebird RDBMS was how to get copy of consice data and not restarting server? I needed to make such backup once a two hours and send it to backup server.
In order to do this I used internal “replication” of Firebird called “shadowing“. Creating of shadow copy is the process of copying file to new location, deactivating triggers and thus created copy is ready for reflecting changes made on “master” database file.
It was first step – obtaining clear copy. Second step is about how to drop shadow file and have shadow file?
I viewed Firebird sources corresponding to this operation and found that before shadow file is to be removed, server tries to close all operations on this file (all data concerning this are stored in RAM). Shortly before phisical removing of file the full path is checked in the system table. So the second trick was to change path to an unexisting file. The server does not check if the appropriate file has been removed so the operation finishes without errors. Everything goes fine? So you have copy of your database file made by server – obviously it is shadow file so you have to activate it for further using.
Below I present bash script which is responsible for these operations:
#!/bin/bash
User='sysdba'
Passwd='YourPassword'
DbFileName='/path/to/your.gdb'
Host='127.0.0.1'
HotcopyFile="/path/to/your.shd"
HotcopyTmp="/tmp/hotcopy.sql"
if [ -f "$HotcopyFile" ]; then
rm -v "$HotcopyFile";
fi
if [ -f "$HotcopyTmp" ]; then
rm -v "$HotcopyTmp";
fi
# Create shadow
touch "$HotcopyTmp";
echo -e "CONNECT '$DbFileName' user '$User' password '$Passwd';\ncreate shadow 2 manual '$HotcopyFile';\ncommit;\nshow database;" > "$HotcopyTmp";
echo -e "update RDB\$FILES set RDB\$FILES.rdb\$file_name='x' WHERE RDB\$SHADOW_NUMBER = 2;\ncommit;" >> "$HotcopyTmp";
echo -e "DROP SHADOW 2;" >> "$HotcopyTmp";
echo -e "commit;\n" >> "$HotcopyTmp";
/opt/firebird/bin/isql -q -i "$HotcopyTmp";
# Make clean
rm -v "$HotcopyTmp"
echo "This is my copy of database file $HotcopyFile"
This information is priceless! Thank you for going to the trouble to post it.