我想检查 SQL 服务器数据库是否被修改。检查数据库被修改的原因是为了备份(sql 数据库备份)目的。所以我将首先进行完整备份,如果有任何数据插入、修改或任何结构或任何更改,那么我必须确定数据库中有一些更改并备份数据库。
可以根据频率(每天、每小时等)检查数据库中的变化。mdf 或 ldf 文件的修改日期不能用于检查数据库是否被修改。差异备份仅备份自上次备份以来的更改,但它有所不同,即使自上次备份以来没有更改,它也会进行备份,但大小会非常小(以 kb 为单位,您可以轻松测试)。
在 Windows NTFS 文件系统中,每个文件都存在 USN 日志,通过使用它我们可以检查文件是否被修改,如果修改,我们可以备份文件。这也在大多数备份软件中实现。
那么如何检查上次备份后是否对数据库进行了任何更改,以便在检测到任何更改时进行备份?
Aar*_*and 14
You can't rely on things like journaling or physical file changes to see if data has changed. I hesitate to mention LSNs because I certainly don't want to encourage any attempt down that road. Trying to do this just to determine whether it might not be worth it to actually go ahead and take a log backup is a disaster waiting to happen.
Take full backups on your current schedule. Take log backups such that your recovery objectives are met. For example, if your business stakeholders state that it is not acceptable to have more than 5 minutes of data loss, back up the log every 5 minutes (and assume that disaster can strike at 4:59.997 since the last log backup).
Sorry, but your approach does not make sense. You are trying to optimize something that is already pretty optimal - SQL Server is pretty good about resource usage and creating small diff/log backup files when there have been few or no changes. What you are attempting to do is like trying to get better gas mileage by wiping a bug off your bumper. Just take the backups. I like the analogy Thomas made: "the juice isn't worth the squeeze."
如果不出意外,每 5 分钟间隔代表一个日志备份文件将是一致且易于自动化的解决方案。如果您因为(您认为)“没有改变”而跳过其中一些备份,那么围绕它们自动化解决方案将变得更加困难,并且很难确定备份是由于该原因丢失还是实际上丢失了。
归档时间: |
|
查看次数: |
2026 次 |
最近记录: |