SQL Clone 3

Help for older versions available.

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

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.

  1. # 'refresh' all clones to use a newer image
  2. Connect-SqlClone -ServerUrl 'http://sql-clone.example.com:14145'
  3.  
  4. $oldImageName = 'Forex_20170301'
  5. $newImageName = 'Forex_20170302'
  6.  
  7. $oldImage = Get-SqlCloneImage -Name $oldImageName
  8. $newImage = Get-SqlCloneImage -Name $newImageName
  9.  
  10. $oldClones = Get-SqlClone | Where-Object {$_.ParentImageId -eq $oldImage.Id}
  11.  
  12. foreach ($clone in $oldClones)
  13. {
  14. $thisDestination = Get-SqlCloneSqlServerInstance | Where-Object {$_.Id -eq $clone.LocationId}
  15.  
  16. Remove-SqlClone $clone | Wait-SqlCloneOperation
  17.  
  18. "Removed clone ""{0}"" from instance ""{1}"" " -f $clone.Name , $thisDestination.Server + '\' + $thisDestination.Instance;
  19.  
  20. $newImage | New-SqlClone -Name $clone.Name -Location $thisDestination | Wait-SqlCloneOperation
  21.  
  22. "Added clone ""{0}"" to instance ""{1}"" " -f $clone.Name , $thisDestination.Server + '\' + $thisDestination.Instance;
  23. }
  24. # Remove the old image
  25. Remove-SqlCloneImage -Image $oldImage;

Didn't find what you were looking for?