不带时间戳的 SQL Server 数据库备份

发布于 2024-12-21 08:51:28 字数 656 浏览 0 评论 0原文

我使用下面的行来备份 Microsoft SQL Server 2008 数据库:

BACKUP DATABASE @name TO DISK = @fileName WITH COMPRESSION

鉴于数据库没有更改,重复执行此行会生成大小相同但内部差异很大的文件。

如何为同一未更改的数据库创建重复的 SQL Server 备份,以提供相同的字节精确文件?我想简单的 BACKUP DATABASE 调用会在备份介质中添加一些时间戳或其他一些元信息,有没有办法禁用或删除此添加?

或者,如果不可能,是否有一种相对简单的方法来比较两个备份,看看它们是否会恢复完全相同的数据库状态?

更新:我的备份比较观点是,我每天都会备份无数数据库,但大多数数据库不会经常更改。对于大多数人来说,每年更换几次是很正常的。因此,基本上,对于所有其他 DBMS(MySQL、PostgreSQL、Mongo),我使用以下算法:

  • 执行新的每日备份
  • 将新备份与最新的旧备份进行比较
  • 如果数据库未更改(即备份)匹配),删除我刚刚创建的新每日备份

该算法适用于我们之前遇到的所有 DBMS,但是,可惜的是,由于不可重复的 MSSQL 备份,它失败了。

I'm using the following line to backup a Microsoft SQL Server 2008 database:

BACKUP DATABASE @name TO DISK = @fileName WITH COMPRESSION

Given that database is not changing, repeated execution of this line yields files that are of the same size, but are massively different inside.

How do I create repeated SQL Server backups of the same unchanged database that would give same byte-accurate files? I guess that simple BACKUP DATABASE invocations add some timestamps or some other meta information in the backup media, is there a way to disable or strip this addition?

Alternatively, if it's not possible, is there a relatively simple way to compare 2 backups and see if they'll restore of the exactly same state of the database?

UPDATE: My point for backup comparison is that I'm backing up myriads of databases daily, but most databases don't change that often. It's normal for most of them to change several time per year. So, basically, for all other DBMS (MySQL, PostgreSQL, Mongo), I'm using the following algorithm:

  • Do a new daily backup
  • Diff new backup with the most recent of the old backups
  • If the database wasn't changed (i.e. backups match), delete the new daily backup I've just created

This algorithm works with all DBMSes we've encountered before, but, alas, it fails because of non-repeatable MSSQL backups.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-12-28 08:51:28

正如您所猜测的,备份目录的一部分包括备份的日期和时间。 WITH COMPRESSION 选项压缩备份以节省空间,但由于压缩算法的工作方式,文件中的一点点更改都会导致整个文件发生更改。

如果您不希望有如此多的差异,请删除压缩选项,但比较备份文件并不是正确的方法。

如果您的数据库变化很小,那么增量备份或差异备份可能更有用。

然而,您似乎陷入了一个名为 XY Problem 的经典陷阱,因为您询问您尝试的解决方案而不是您的实际问题。是什么促使您尝试比较数据库?

As you guess part of the backup catalog includes the date and time of the backup. The WITH COMPRESSION option compresses the backup to save space but a little change in the file will cause changes throughout the file because of the way compression algorithms work.

If you don't want so many differences then remove the compress option, but comparing backup files isn't the way to go.

If you have a database that changes little then incremental or differential backups may be of more use.

However you seem to have fallen into a classic trap called the XY Problem as you are asking about your attempted solution rather than your actual problem. What is prompting you to try and compare databases?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文