These pages cover SQL Clone 3, which is not the latest version. Help for other versions is also available.
'Refresh' all clone databases to use an updated image
Published 02 March 2017
If you are regularly creating images so that you have a latest possible copy of a database available, you may want to migrate clones to that new image.
This script will remove existing clone databases for a named image, then create new clone databases in the same location for an updated image.
The clone databases will be removed immediately by this script, and any changes made to them will be lost. The old image will also be removed.
- # 'refresh' all clones to use a newer image
- Connect-SqlClone -ServerUrl 'http://sql-clone.example.com:14145'
- $oldImageName = 'Forex_20170301'
- $newImageName = 'Forex_20170302'
- $oldImage = Get-SqlCloneImage -Name $oldImageName
- $newImage = Get-SqlCloneImage -Name $newImageName
- $oldClones = Get-SqlClone | Where-Object {$_.ParentImageId -eq $oldImage.Id}
- foreach ($clone in $oldClones)
- {
- $thisDestination = Get-SqlCloneSqlServerInstance | Where-Object {$_.Id -eq $clone.LocationId}
- Remove-SqlClone $clone | Wait-SqlCloneOperation
- "Removed clone ""{0}"" from instance ""{1}"" " -f $clone.Name , $thisDestination.Server + '\' + $thisDestination.Instance;
- $newImage | New-SqlClone -Name $clone.Name -Location $thisDestination | Wait-SqlCloneOperation
- "Added clone ""{0}"" to instance ""{1}"" " -f $clone.Name , $thisDestination.Server + '\' + $thisDestination.Instance;
- }
- # Remove the old image
- Remove-SqlCloneImage -Image $oldImage;