Subject RE: [firebird-support] GBAK error on the running database
Author Nigel Weeks
I have a script that programatically goes through all databases in a
directory, backs them up, restores them to a temporary database, shows a
list of tables to make sure the database restored correctly, drops the
temporary database, compresses the backup, and goes on with the next one...


----------------- fb_backups.sh -------------------------
#!/bin/sh


########################################################
#
# Tweak these to suit your system
#
########################################################
db_loc="/raid/db"
backup_loc="/raid/www/data/remote_sync/database_backups"
restore_db="localhost:/raid/db/temp_restore.fdb"
db_user="sysdba"
db_pass="masterkey"

# Command paths
isql="/usr/local/bin/isql"
gbak="/usr/local/bin/gbak"
date="/bin/date"
gzip="/usr/bin/gzip"
tar="/usr/bin/tar"





########################################################
#
# You shouldn't need to change anything below this line
#
########################################################


# Move to the database directory
cd ${db_loc}

for i in `ls *.fdb`
do
#stamp=`${date} "+_%Y%m%d%H%M%S"`
stamp=""

echo `${date} "+%Y-%m-%d %H:%M:%S"` ":
=======================================
"
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Found database '${i}'"
echo `${date} "+%Y-%m-%d %H:%M:%S"` ":
=======================================
"

# Backup each database to a file
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Started Backing up '${i}' to
'${backup_
loc}/${i}.fbk'"
time ${gbak} -b -v -t -user ${db_user} -pass ${db_pass}
localhost:${db_loc}/${
i} ${backup_loc}/${i}${stamp}.fbk

# Attempt to restore each database to a temporary database
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Attempting restore of
'${backup_loc}/${
i}${stamp}.fbk' to temporary database '${restore_db}'"
time ${gbak} -r -user ${db_user} -pass ${db_pass}
${backup_loc}/${i}${stamp}.f
bk ${restore_db} && echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Restore of
'${backup_
loc}/${i}${stamp}.fbk' was successful" || echo `${date} "+%Y-%m-%d
%H:%M:%S"` ":
!!! RESTORE FAILED !!!"

# Peek inside the temporary database
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Listing tables in restored
database"
echo "show tables;" | ${isql} -u ${db_user} -p ${db_pass} ${restore_db}


# Drop the temporary database
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Dropping temporary database"
echo "drop database;" | ${isql} -u ${db_user} -p ${db_pass} ${restore_db}

# Compress each backup file
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Compressing
'${backup_loc}/${i}${stamp}
.fbk' to '${backup_loc}/${i}${stamp}.fbk.gz'"
${gzip} -9c ${backup_loc}/${i}${stamp}.fbk >
${backup_loc}/${i}${stamp}.fbk.gz
${gzip} -l ${backup_loc}/${i}${stamp}.fbk.gz
echo `${date} "+%Y-%m-%d %H:%M:%S"` ":
=======================================
"
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": Finished with database '${i}'"
echo `${date} "+%Y-%m-%d %H:%M:%S"` ":
=======================================

"

done
${tar} cvfz ${backup_loc}/archive.tgz ${backup_loc}/*.fbk
echo `${date} "+%Y-%m-%d %H:%M:%S"` ": All database backups completed"


--------------------- end of file -------------------


-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com]On Behalf Of Dipesh
Sent: Wednesday, 15 November 2006 1:26 PM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] GBAK error on the running database


Hi,

I am trying to run gbak and restore on the database which is running
by following the steps mentioned below. (This is in my script)

1) Stop the database. (killing firebird server)
2) Start the database.
3) gfix shut (forcefully shutting the database)
4) Copying the database as repair_myDB.fdb
5) gfix validate (Validate the copied database)
6) gfix mend (Mend the validated database i step5)
7) gfix validate (Validate the mended database again)
8) gbak validated database from step 7 into my backup location.
This step creates a backup file but the process gbak in windows is
running forever and not returning. When i manually run the same
command i.e. gbak it works perfectly fine and creates a file which is
larger than the file created by the hanging process.
9) gbak restore from the backup file created in step 8
10) gfix validate (validate the restored database file)
11) stop the database server.

12) Rename the main database file i..e myDB.fdb to myDB_timestamp.fdb
13) Rename my restored file to the same file as it was in step1 i.e.
myDB.fdb

13) Restart the database.

If I manually do steps 8 and 9 it works fine but when I am running
this script programatically it is halting somewhere. When I killed the
process and tried to restore the database from the backup file
generated from this halted process it gave me following error.

Done with volume #1,
"Path_to_backup_file\Backup_20061114_161716_myDB.fdb.fbk"
Press return to reopen that file, or type a new
name followed by return to open a different file.
Name:
=> I have pressed enter above.
Expected volume number 2, found volume 1
gbak:

Could not read from file
"Path_to_backup_file\Backup_20061114_161716_myDB.fdb.fbk"

Done with volume #1,
"Path_to_backup_file\Backup_20061114_161716_myDB.fdb.fbk"
Press return to reopen that file, or type a new
name followed by return to open a different file.
Name:
=> I have pressed enter above.
Expected volume number 2, found volume 1
gbak:

Could not read from file
"Path_to_backup_file\Backup_20061114_161716_myDB.fdb.fbk"

Done with volume #1,
"Path_to_backup_file\Backup_20061114_161716_myDB.fdb.fbk"
Press return to reopen that file, or type a new
name followed by return to open a different file.
Name: 1
=> I have pressed 1 above.
gbak: ERROR: expected backup description record
gbak: Exiting before completion due to errors

I have run my above script programatically on the database which were
not running. I am doing something wrong above.

Any input to figure out this problem will be highly appreciated.

Thank you.
Regards,

Dipesh






[Non-text portions of this message have been removed]