views:

726

answers:

3

I am working on my first WinForms application with a Firebird database shared over a network. Now I wonder how should I ensure database backup and restoring?

Up till now, my applications used embedded databases (SQLite), so I was sure that only my application accessed the database. The application itself was responsible for the backups and restores. I could simply copy the database file and that's it.

The backup was made:

  1. Automatically at each application start
  2. Automatically every week
  3. Manually by user

When the user wanted to restore from backup, he could do this anytime and he could choose from any type of backup. All directly from my application.

For the new application, I've moved from SQLite to Firebird. I've chosen Firebird because the application will run with embeded database by default, but can be used also with classic server. With Firebird, I can use both embedded and server with the same database file.

The problem is that when the database will run on a server, there can be many users working with the database at the same time, so I don't know how to make backup and restore. Should I omit the backup/restore functionality in my app and let the admin make the backups on the server? Or should my app include backup and restore?

The shared database is simply totally new to me, so I don't know the best practices. Anyway, the database will be pretty small and there will be only several users working at the same time.

Thanks, Petr

A: 

If you are using a shared database, then you should probably take the backup/restore process out of your application, otherwise one user could corrupt or eliminate the work of another user.

Jacob G
+2  A: 

Don't copy the database file, it will corrupt the database.
Firebird is a relational database server. gbak is the official application to run hot backups.
Check this out: http://firebirdfaq.org/cat5/

Douglas Tosi
Copying the database file is fine if you snapshot the block device or filesystem first (e.g. with whatever Microsoft thing Lars suggested)
MarkR
A: 

On a shared server, you have several options for making backups:

  • Use a file-backup tool that supports Microsoft Volume Shadow Copy. This will take a snapshot of your database. Firebird was designed to "survive" such backups. However, restoring such a backup is like having a power failure, but on the other hand, if you need to instruct an IT department how to do it and make surveillance, this is a serious option.

  • Use gbak.exe to make a copy of the database while it is in use, into a backup file. Then, make a backup of that. This is the recommended method, but in order for this to work properly, you need to inspect the exit code of gbak.exe to check that no error happened. Not all IT departments are able to do that.

However, on a shared server, you must always be paranoid: Most backups in big organizations cannot be restored, and usually the problem is that humans make mistakes. Therefore, I can recommend the third option, which is basically the combination of the first two:

  • Use gbak.exe to make a copy of the database into a backup file. If possible, make surveillance on the exit code of gbak.
  • Use a Microsoft Volume Shadow Copy enabled backup program to make a backup of both the primary database and the backup file.

This should give you a nice backup file to restore, and if gbak should have failed and noone noticed, you can fall back to the raw snapshot of the running database file. Several people must make several mistakes for this to fail.

Lars D