SQL Clone 3

Help for older versions available.

Purge old images which don't have clones

If you are regularly creating images on a schedule, you may wish to clear out the older ones. This script will remove images older than a given date, as long as they don't have clone databases dependent on them (in which case warn in the output).

This script will remove images without any further warning. You will need to test this and add protections appropriate to your environment before live use.

  1. Connect-SqlClone -ServerUrl 'http://sql-clone.example.com:14145'
  2.  
  3. $imageTimeToLiveDays = 7;
  4.  
  5. $oldImages = Get-SqlCloneImage | Where-Object {$_.CreatedDate -le (Get-Date).AddDays(0-$imageTimeToLiveDays)}
  6.  
  7. foreach ($image in $oldImages)
  8. {
  9. $clones = Get-SqlClone -Image $image
  10. if (!($clones -eq $null))
  11. {
  12. "Will not remove image {0} because it has {1} dependent clone(s)." -f $image.Name, $clones.Count
  13. }
  14. else
  15. {
  16. Remove-SqlCloneImage -Image $image
  17. "Removed image {0}." -f $image.Name
  18. }
  19. }

Didn't find what you were looking for?