gbak: ERROR:could not drop database C:\test.fdb (database might be in use)
gbak: ERROR: Exiting before completion due to errors
Nevertheless, the replaced database file is removed by previous gbak call, so the next call of the same gbak command is successfull (since the file to overwrite is now missing). Once the database file exists, however, gbak fails again.
To be sure that the file is really not in use, I even tried to stop the server before the gbak call, but it didn't help.