Documentation

Creating a clone from an image using SQL Clone

Having created an image, many clones, either on the same server or on network servers, can reference it, independently. For each clone, SQL Clone creates a VHD, called a differencing disk (or Diff file), on the local instance, with a connection back to the image, accessible to the clone via a mount point. This means that each clone created from an image can access all those same image bytes. All that's stored locally, in the differencing disk, are data pages containing changes made directly to the local clone database.

This means that even for a source database in the terabyte range, each clone will initially be only tens of megabytes in size. When you make data or structural changes to a clone database, SQL Server writes the change to the differencing disk. Any change you make to a clone database will have an effect only on that clone, will be isolated from the image, and will have no impact at all on the integrity or performance of the source database.

When you query data, the operating system reconstructs the required data pages from the differencing disk plus the database files in the original image. All of this is invisible to SQL Server, which works with the clone just as it would with any other database.

Specify the source image and clone location

From the SQL Clone web client:

  1. Click the Clone button for the source image, or click Create Clone from the left-hand menu and select the source image from the dropdown
  2. Choose a destination SQL Server instance on which to create the clone
    1. If the Clone destination instance is a newer SQL Server version than the instance hosting the source database, SQL Server will upgrade the clone database to run on the newer version, and writes those changes into the local differencing file.
    2. If the Clone destination instance is an older SQL Server version, you will see an error during clone creation.
  3. Give the database clone a name, perhaps referencing the name of the parent image
  4. Click Create Clone! This will take just a few seconds.

Having created a clone, you can query and work with it from SSMS, just as any normal database. You can create multiple clones from the same image, for example to perform parallel database testing, or simply so that each developer can work with his or her own local copy of the database, with realistic data.

By default, SQL Clone creates the clones in the SQL Server instance's Data folder, in a clones subdirectory, although this location may change in future (you can choose a different location by specifying command-line arguments to the agent installer).

At this location, and you'll find a folder holding each of the clones created on that machine. For each clone, you'll also see the local differencing disk, disk.vhd, and the VhdMount point, a 'symbolic link;' to the remote 'mounted volume, inside of which is a Data folder containing the data and log files for the database. Remember that these are made accessible to SQL Server via the VHD mount point to the remote data image; this is entirely transparent to SQL Server.

Summary

Most clones will have a finite lifespan. For example, during testing, we might spin up a clone, run the tests, then immediately dispose of it. We can keep track of what clones exist for what data images via the Dashboard section of the SQL Clone server web app. From here, we can delete clones, and delete images, having first deleted all associated clones.

If you’ve installed the PowerShell cmdlets, you can run PowerShell scripts to automatically tidy up images and clones after a set period.