如何备份Firebird数据库?
我正在开发我的第一个 WinForms 应用程序,其中包含通过网络共享的 Firebird 数据库。现在我想知道如何保证数据库的备份和恢复?
到目前为止,我的应用程序使用嵌入式数据库(SQLite),因此我确信只有我的应用程序访问数据库。应用程序本身负责备份和恢复。我可以简单地复制数据库文件,仅此而已。
进行备份:
- 每次应用程序启动时自动
- 每周自动
- 由用户手动
当用户想要从备份恢复时,他可以随时执行此操作,并且可以从任何类型的备份中进行选择。全部直接来自我的应用程序。
对于新应用程序,我已从 SQLite 迁移到 Firebird。我选择 Firebird 是因为该应用程序默认情况下将使用嵌入式数据库运行,但也可以与经典服务器一起使用。借助 Firebird,我可以使用具有相同数据库文件的嵌入式和服务器。
问题是当数据库运行在服务器上时,可能有很多用户同时使用数据库,所以我不知道如何进行备份和恢复。我是否应该忽略应用程序中的备份/恢复功能并让管理员在服务器上进行备份?或者我的应用程序应该包含备份和恢复吗?
共享数据库对我来说是全新的,所以我不知道最佳实践。无论如何,数据库将非常小,并且只有几个用户同时工作。
谢谢,彼得
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:
- Automatically at each application start
- Automatically every week
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要复制数据库文件,它会损坏数据库。
Firebird 是一个关系数据库服务器。 gbak是运行热备份的官方应用程序。
看看这个:http://firebirdfaq.org/cat5/
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/
在共享服务器上,您有多种备份选项:
使用支持 Microsoft 卷影复制的文件备份工具。这将拍摄您的数据库的快照。 Firebird 被设计为能够在此类备份中“幸存”。但是,恢复此类备份就像断电一样,但另一方面,如果您需要指导 IT 部门如何执行此操作并进行监视,那么这是一个严肃的选择。
使用 gbak.exe 将正在使用的数据库复制到备份文件中。然后,对其进行备份。这是推荐的方法,但为了使其正常工作,您需要检查 gbak.exe 的退出代码以检查是否发生错误。并非所有 IT 部门都能做到这一点。
然而,在共享服务器上,您必须始终保持偏执:大型组织中的大多数备份都无法恢复,而且通常问题是人为错误。因此,我可以推荐第三个选项,它基本上是前两个选项的组合:
这应该会给你一个很好的备份文件来恢复,如果 gbak 失败并且没有人注意到,你可以回退到正在运行的数据库文件的原始快照。必须有几个人犯几个错误,这个计划才会失败。
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:
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.
如果您使用共享数据库,那么您可能应该从应用程序中删除备份/恢复过程,否则一个用户可能会破坏或消除另一用户的工作。
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.
您可以在 C# 中使用 nbackup,如下所示:
如果您想在备份时阻止数据库
请不要忘记取消阻止,
如果您想关闭所有连接,
请尝试: FbConnection.ClearAllPools();
You can use nbackup in C# as follows:
In case you want to block the database while making the backup
Don't forget to unblock
if you want to close all the connections try:
FbConnection.ClearAllPools();