4 April 2017
4 April 2017

Backup and restore of a SQL Clone

What if you now do development work on a clone, but you to continue working on you own local clone while ‘disconnected’, such as when travelling? One simple option if the original database contains no private data, or the image has been masked, is to performance a normal backup and restore operations the clone, although you'll now be working with a normal, full-sized database.

With SQL Clone, I can create multiple copies of my database, for testing, very quickly. First, I create an image of the source database, and then from that image I can create multiple clones. Each copy, or clone, appears to SQL Server as a normal database, and yet occupies a fraction of the disk space of the full database from which the clone was created.

I can work on my database clone locally, making changes, which are saved to a local differencing file. However, when I query the clone database, SQL Clone reads any other data, ie, any data I’ve not changed locally, from the data image file. However, what if I want to continue working on my local clone while ‘disconnected’, such as when travelling? At this point, I have no connection to the data image location, unless the image is local, or to SQL Clone Server (required for clone maintenance and management).

However, since SQL Server sees each clone as a normal database, I can perform normal backup and restore operations on a clone, just like any other database. I can back up my clone, copy the backup file to the machine on which I want to work while disconnected, and then perform a restore operation. I’d only want to do this for database backups that don’t contain any sensitive or PII data.

When we capture a full database backup of a clone, we capture the local changes, plus all the unchanged objects and data from the source data image, which means that while disconnected, I’m working with a normal, full-sized database.

Let’s see how all this works.

Working with clones

I’m starting from a data image, called PartsBase, from my PartsUnlimited database. If you don’t know how to create a data image, there is a good getting started post from Tony Davis.

I want to create a clone from this image, so that I can work on it, and develop code, on my local development database. I’ll call the clone PartsUnlimited_Clone, so that when I access it in SSMS, I’m aware that it’s a clone.

Creating the clone takes only a few seconds, and I see it in SSMS and work with this database during development, just like any other database. In my case, I’ll add a new stored procedure.

Having altered my database clone, I now have a change stored locally, on my development workstation, which isn’t in the original data image.

Backup the clone

Suppose I want to move a copy of this database elsewhere? Perhaps, I want to continue working on an existing clone, to which I’ve made development changes while connected, while working remotely, such as during an upcoming flight to England, with no connection to the remote data image or to SQL Clone Server.

Let’s set that up. First, I’ll make a backup of the clone. I can do this because SQL Server sees the clone as a normal SQL Server database. All the structures and data pages appear to be in the database.

Now I have this file in the backup folder on my development workstation.

I’ll copy this backup file to the backup folder of the SQL Server instance on my disconnected machine, in this case my laptop. Since this is a normal backup, it’s about the same size as my original PartsUnlimited database, something I need to be aware of. While SQL Clone saves me disk space, SQL Server backup and restore doesn’t. I need to make sure I’ve enough space for the backup file and the restored data/log files on my laptop.

Restoring the backup

From this point on, I’m just working with a normal, full database backup, but one that incorporates the development changes I made to my clone. If I were running SQL Clone Server on my laptop, I could consider creating a new data image locally, from the backup, and then clone from that image, but since I’m not, I’ll just perform a normal database restore operation.

All I need to do is connect to the instance on my local laptop and perform a restore, just the same as any normal SQL Server restore. First, choose the restore database option:

Next I select the backup file as my device and, as we can see, the default database name and original instance are listed. In this case, I also need to click the move files checkbox on the Files tab since the paths on my laptop are different from those on my development workstation.

I’ll change the name of the restored database to PartsUnlimited, since this isn’t a cloned database, and click OK to restore the database. Once that’s done, I see it in my new instance. I have my new stored procedure as well, which is what I expect. This is a normal SQL Server backup and restore.

Now I’m set for my flight and can work in the air. When I get back to the office, if I want to share this with others, or use it in test environments as a part of my CI process, I can make a new SQL Clone image and additional clones from this. If I’ve made any development changes. I’d want to ensure these are committed to my VCS.

Cloned databases are SQL Server databases

SQL Server sees the cloned database as a user database. That means that I can treat it as one, including backup and restore. If there are situations where some developers can’t connect to the SQL Clone Server, then backup and restore works to get them a copy of the database. If you want to move databases between SQL Clone installations, such as in remote offices, you can also use this technique to move your databases.

If you have many copies of development and test databases, SQL Clone can potentially save you a lot of provisioning time and a lot of disk space.

Tools in this post

SQL Clone

Create SQL Server database copies in an instant

Find out more

You may also like

  • Article

    A behind the scenes glimpse of SQL Clone

    It has always been a difficult task to provision development and test environments so that they reflect as closely as possible what’s present in production. With the rise of containerization and Infrastructure as Code (IaC) technologies, some parts of this are becoming much easier. We can automate the process of spinning up and configuring new virtual

  • Article

    Easing the transition from shared to dedicated database development

    Working in dedicated development environments for the database is the ideal for many. This is the message we frequently hear throughout the industry from thought leaders, at conferences, and in many written pieces about implementing best practices. Yet 70% of developers still work in shared environments, as highlighted in the 2020 State of Database DevOps

  • Article

    Testing Databases: What's Required?

    Phil Factor reviews the various types of database test that need to run during development work, what sort of test data they require, and the challenges with managing this data, and in keeping the test cell stocked with the correct database, and data, in a way that allows rapid cycles of database testing.

  • Article

    Creating Multiple Masked Databases with SQL Provision

    Chris Unwin explains how SQL Provision can create copies of multiple databases, each masked consistently, and deliver them as a group. This is useful when, for example, you are working with a Data Warehouse that contains several cross-database relationships.

  • Article

    Safely Deleting Clones and Images during Database Development and Testing

    Whenever you’re ready to refresh a test cell with the latest database version, you need a safe way to drop the current set of clones, and the parent image, without losing any unsaved work. Phil Factor provides a PowerShell script that automates this process so it runs in the time it takes to grab a coffee, after which can quickly deploy the new clones.

  • Forums

    SQL Clone Forum

    Create SQL Server database copies in an instant