使用 Windows DFS 复制的 SQLite 备份
SQLite backup using Windows DFS Replication
我有一个使用 SQLite 进行存储的应用程序,我想知道使用 Windows DFS Replication 将数据库文件备份到安装了该应用程序的冷备用实例的第二台服务器是否安全.
可能相关的详细信息:
- 虽然 DFS 支持双向复制,但在这种情况下,它只是写入主数据库文件,因此复制实际上是单向的。
- 主数据库文件与写入它的进程位于同一台服务器上。
- 目前 SQLite 配置为在必要时使用标准 Rollback Journal, but I could switch to Write-Ahead Log。
如果 DFS 在复制期间锁定主数据库文件,那么我认为只要锁定时间不长,这种方法就可以工作。但是我找不到关于 DFS 如何实现的足够信息。
更新:我已经在测试环境中实现了它,并且已经 运行 好几天了。在那段时间里我没有遇到任何问题,所以我很想采用这个解决方案。
考虑到 DFS Replication 面向文件和文件夹:
DFS Replication is an efficient, multiple-master replication engine
that you can use to keep folders synchronized between servers across
limited bandwidth network connections.
如果您关心一致性并保留所有数据,我可能会尽量避免使用它,如 SQLite backup documentation 所述:
Historically, backups (copies) of SQLite databases have been created
using the following method:
- Establish a shared lock on the database file using the SQLite API (i.e. the shell tool).
- Copy the database file using an external tool (for example the unix 'cp' utility or the DOS 'copy' command).
- Relinquish the shared lock on the database file obtained in step 1.
This procedure works well in many scenarios and is usually very fast.
However, this technique has the following shortcomings:
- Any database clients wishing to write to the database file while a backup is being created must wait until the shared lock is relinquished.
- It cannot be used to copy data to or from in-memory databases.
- If a power failure or operating system failure occurs while copying the database file the backup database may be corrupted
following system recovery.
对于 DFS,它甚至不会在复制之前锁定数据库。
我认为你最好的选择是使用某种热复制,你可能想使用 SQLite Online Backup API, you could check this tutorial on creating a hot backup with the Online Backup API。
或者如果您想要更简单的东西,您可以尝试使用 SymmetricDS,一个与 SQLite 兼容的开源数据库复制系统。
还有其他选项(如 litereplicator.io),但这个已关闭源代码并且仅限于旧 SQLite 版本和约 50MB 大小的数据库
ps。如果您真的需要 HA、复制或此类功能,我可能会放弃 SQLite。根据您选择的编程语言,很可能您已经抽象了 DB 层,您可以使用 MySQL 或 PosgreSQL。
我有一个使用 SQLite 进行存储的应用程序,我想知道使用 Windows DFS Replication 将数据库文件备份到安装了该应用程序的冷备用实例的第二台服务器是否安全.
可能相关的详细信息:
- 虽然 DFS 支持双向复制,但在这种情况下,它只是写入主数据库文件,因此复制实际上是单向的。
- 主数据库文件与写入它的进程位于同一台服务器上。
- 目前 SQLite 配置为在必要时使用标准 Rollback Journal, but I could switch to Write-Ahead Log。
如果 DFS 在复制期间锁定主数据库文件,那么我认为只要锁定时间不长,这种方法就可以工作。但是我找不到关于 DFS 如何实现的足够信息。
更新:我已经在测试环境中实现了它,并且已经 运行 好几天了。在那段时间里我没有遇到任何问题,所以我很想采用这个解决方案。
考虑到 DFS Replication 面向文件和文件夹:
DFS Replication is an efficient, multiple-master replication engine that you can use to keep folders synchronized between servers across limited bandwidth network connections.
如果您关心一致性并保留所有数据,我可能会尽量避免使用它,如 SQLite backup documentation 所述:
Historically, backups (copies) of SQLite databases have been created using the following method:
- Establish a shared lock on the database file using the SQLite API (i.e. the shell tool).
- Copy the database file using an external tool (for example the unix 'cp' utility or the DOS 'copy' command).
- Relinquish the shared lock on the database file obtained in step 1.
This procedure works well in many scenarios and is usually very fast. However, this technique has the following shortcomings:
- Any database clients wishing to write to the database file while a backup is being created must wait until the shared lock is relinquished.
- It cannot be used to copy data to or from in-memory databases.
- If a power failure or operating system failure occurs while copying the database file the backup database may be corrupted following system recovery.
对于 DFS,它甚至不会在复制之前锁定数据库。
我认为你最好的选择是使用某种热复制,你可能想使用 SQLite Online Backup API, you could check this tutorial on creating a hot backup with the Online Backup API。
或者如果您想要更简单的东西,您可以尝试使用 SymmetricDS,一个与 SQLite 兼容的开源数据库复制系统。
还有其他选项(如 litereplicator.io),但这个已关闭源代码并且仅限于旧 SQLite 版本和约 50MB 大小的数据库
ps。如果您真的需要 HA、复制或此类功能,我可能会放弃 SQLite。根据您选择的编程语言,很可能您已经抽象了 DB 层,您可以使用 MySQL 或 PosgreSQL。