Subject Re: Can I copy the embedded database file on the fly?
Author Adam
> Is it safe to make a file copy of the embedded database file ***.fdb
> while the application is still connected to that file?

It depends if the engine does anything to the file during the time you
take the backup. I wouldn't risk it because asides from what your
application requests of the server, there is also the garbage
collection thread that may be running. Firebird 2 will introduce
nbackup which you could use to make this work, but Firebird 2 is
release candidate (not production stable yet). You could also do it by
completely disconnecting the database (and some components require you
unload it as well before it totally releases the fdb file lock).

> The
> applications is multi-threaded but access to the database is
> synchronized by the use of semaphore and all changes to the database
> via insert/update/delete are commited immediately before releasing the
> semaphore by the accessing thread.

Nothing like driving along with your handbrake on. Let the bird out of
its cage. (that could have gone in the slogan suggestions ;)

Firebird can do more than one thing at a time, and there is no need to
prevent two actions from occurring at the same time if they have
nothing in common. You can use WAIT or NOWAIT to determine how any
conflicts should be resolved.

> My application is a daemon application and it nevers shutdown so I
> programmed the application to backup the database file by file copy on
> the fly at midnight upon a configurable number of days has elapsed.

Not an unusual problem. You want a hot backup. Luckily, even embedded
supports this but there is a bit of a twist. The gbak process can not
connect to it, but if your daemon was to make use of the service
manager, it would work fine. Furthermore, you could do this in a
different thread and there would be no impact on your daemon (except
it may run a little slower because it must compete for disk resources).