SQL Server 2008 差异数据库

发布于 2024-12-09 06:17:39 字数 665 浏览 1 评论 0原文

所以事情是这样的:

背景

  • Hyper-V VM 可以处理差异磁盘模式,在这种模式下,可以将原始 VHD 文件设置为只读状态,并创建一个新的 vhd 来跟踪,并持续存在变化。这里的优点是您可以轻松创建新的虚拟机,而无需重新安装 Windows 等。

问题

  • 我正在寻找类似的东西,但是针对 SQL Server 数据库。我们在本地进行所有开发,然后我们有一个运行 X 个实例的盒子(每个开发人员 1 个)。然后,我们有一个过程可以复制所做的生产备份并将其恢复到这些实例。完成此操作后,它会签出开发人员选择的(SQL 脚本)分支并在实例上运行脚本。这样他们就可以在实际投入生产之前在生产数据上测试代码。然而,为每个实例拥有所有生产数据库的副本确实很痛苦——最好拥有一组它们并有一个仅保留所做更改的差异选项。这是可能的还是我在做梦?

可能的解决方案

  • 我想到的一个解决方案就是使用实际的差异磁盘 VHD。我将创建一个包含生产备份数据库的基础 VHD,该数据库将在夜间与生产数据库一起修改/创建。然后,我将让它修改/创建差异磁盘并将脚本应用到每个差异磁盘。这样我们就拥有了数据库的 1 个副本,并且开发人员的更改被记录到单独的差异磁盘上。然而,我希望在 SQL Server 中完成这个任务。

So here is the deal:

Background

  • A Hyper-V VM can handle a differencing disk mode, where one can set the original VHD file in a read-only state and create a new vhd which keeps track of, and persists, the changes. The advantage here is you can easily create new VMs without having to reinstall Windows, etc.

Problem

  • What I am looking for is something similar, but for SQL Server databases. We do all of our development locally and then we have a box that has X instances run on it (1 for each developer). We then have a process which copies the production backups that are made and restores them to these instances. After this is complete, it checks-out a branch that a developer chooses (of SQL scripts) and runs the scripts on the instance. This way they can test their code on production data prior to it actually hitting production. However, it is a real pain to have a copy of all our production dbs for each instance-- it would be nice to have 1 set of them and have a differential option which just persists the changes made. Is this possible or am I dreaming?

Possible solution

  • One solution I thought of is just to use an actual differencing disk VHD. I would create a base VHD that has our production backup databases, which would be modified/created night with the production database. I then would have it modify/create differencing disks and apply the scripts to each differencing disk. This way we have 1 copy of the dbs, and the developer's changes are recorded to a separate differencing disk. However, I was hoping to accomplish this in SQL server.

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

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

发布评论

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

评论(1

帅气尐潴 2024-12-16 06:17:39

基本上我得出的结论是尝试自动化差异磁盘的过程,如下所示:

  1. 在网络共享上创建一个新的 VHD - 我们将其称为 NAS1。
  2. 将 VHD 从 NAS1 装载到充当 SQL 处理器的计算机上(我们将其称为 SQLPROCESS1。SQLPROCESS1
  3. 执行以下操作。
    1. 将 BAK SQL 文件从生产环境复制到 SQLPROCESS1(这可能需要一段时间,但整个 #3 可以放入线程应用程序中,因此可以同时复制多个文件并进行恢复)。
    2. 恢复 SQLPROCESS1 上的文件和点数据文件(mdf、ldf)以驻留在新的 VHD 上。
    3. 可选:将 SQL 数据库更改为 SIMPLE 备份模式并使用 SHRINKFILE,因为我们将仅将它们用于开发(并且不需要备份)。这可以节省我们很多空间。
    4. 分离所有数据库。
    5. 分离 VHD。
  4. 在 NAS1 上创建与父级不同的磁盘。
  5. 复制差异磁盘 X 次(根据每个实例或开发人员的需要)。
  6. 可选:我们使用名为 TEST1 的中央服务器进行测试,我们将在此处安装每个差异磁盘 - 每个实例或开发人员 1 个。
    1. 我们首先需要从每个实例中分离所有数据库。
    2. 然后,我们需要卸载/分离现有的差异 VHD(如果有)。
  7. 连接差异磁盘。
  8. 重新附加 SQL Server 中的所有数据库。
  9. 可选:根据开发人员指定从代码存储库分支运行 SQL 脚本。

参考文献:

为了实现自动化,我将使用一组简单的批处理文件、VBS 或 PowerShell。

编辑:刚刚尝试过,效果很好!开发人员现在拥有自己的实例,它只记录他们的更改。

Basically the conclusion I have come to is to try and automate the process of differencing disks as below:

  1. Create a new VHD on a network share- we'll call this NAS1.
  2. Mount the VHD from NAS1 on a machine that acts as a SQL processor (we'll call this SQLPROCESS1.
  3. SQLPROCESS1 performs the following actions.
    1. Copy BAK SQL files from production to SQLPROCESS1 (this might take a while, but this entire #3 could be put into a threaded application, so it could be copying multiple and restoring at the same time).
    2. Restore files on SQLPROCESS1 and point data files (mdf, ldf) to reside on the new VHD.
    3. Optional: Change SQL dbs to SIMPLE backup mode and use SHRINKFILE since we'll be using them solely for development (and don't need backups). This can save us a lot of space.
    4. Detach all dbs.
    5. Detach the VHD.
  4. Create differencing disk from parent on NAS1.
  5. Copy differencing disk X number of times (as needed per instance or developer).
  6. Optional: We use a central server called TEST1 for testing and this is where we are going to mount each differencing disk-- 1 per instance or developer.
    1. We'll first need to detach all dbs from each instance.
    2. Then we'll need to unmount/detach the existing differencing VHDs if there are any.
  7. Attach differencing disk(s).
  8. Reattach all dbs in SQL Server.
  9. Optional: run SQL scripts from a code repository branch as specified per developer.

References:

To automate I'd use a simple set of batch files, VBS, or PowerShell.

Edit: Just tried this and it works great! Developers now have their own instance and it only records their changes.

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