Subject Re: Restoring a database
Author Adam
--- In firebird-support@yahoogroups.com, "Guilherme G G" <guiboy@...>
wrote:
>
> I want to do this from my aplication
>
>
> 1: once the client clicks the restore button the program disconnects
the
> database (and hopefully all connected clients)
>
>
>
> 2: restore the database using REPLACE switch
>
>
>
> 3 Bing the database back online
>
>
>
> The problem is that the command "gfix -shut -force 0 -user
SYSDBA -password masterkey mydb.fdb" does shut down the database,
but the database can't be rewritten if other clients are still
connected, its odd for me, cause I expected that a database that is
"shut down" to have no connected clients, so in this scenario I cant
rewrite the database (it prompts an error saying "could not drop
database X, database might be in use" but if I close all client
applications, then I can make my restore, which is also odd since I am
disconnecting clients from a disconnected database!

It will disconnect the users providing

* The user is not SYSDBA
* The user is not the database OWNER

This is pretty well documented.

Lesson: Do not connect your clients as SYSDBA or the user that created
the database if this is your requirements.

>
>
> It seems to me that that a shutdown database still retains
[*** SYSDBA/OWNER *** ;)] connections, I need a way to purge all
connected clients from the database to release the lock on the file so
the database can be rewritten
> Can I achieve this programmatically?

See above. Another side point, when you begin to restore the database
with the replace switch the first thing it does is to delete the old
one. If the restore fails due to a corrupt backup file, you will be
left with no database and an unrestorable backup of it. You may want
to change the process slightly, rename the fdb file (this will prevent
all connections but will only succeed if no-one is connected) then
restore to a DIFFERENT filename (to prevent people from connecting
during the restore), then rename that file to the correct name.
Alternatively if you use aliases, you can point the alias elsewhere
while you do all this.


Adam