Comments
3 comments
-
Hi,
Your script seems correct. To better investigate the problem, could you send the error message you receive and installed SQL Clone version?
Thanks. -
Hi, We're on version 2.4.5.9041 ,and the error from the deployment is:
This works fine as long as the clone has been deployed already to that server so it can be deleted. -
Hi,
While using Get-SqlClone with Name and Location parameters, you make an exact search for clone. So, if there is no clone with given credentials, you will receive an error. To avoid this, there are two ways:
1. Using try catch
2. Getting all clones of a specific location and try to get your clone name from this list by using powershell
(Get-SqlClone -Location $SqlServerInstance)
There are 2 more usage of Get-SqlClone command. (But these usages can cause to delete more clones on your environment)
1. You can use wildcard (*) with your clone name. For example:
Get-SqlClone -Name 'clone_name*' -Location $SqlServerInstance
With this command, you will receive all clones which starts with "clone_name" for the location you specified. If there is no clone starts with "clone_name", there will be no error message and you will receive null object.
2. You can use Get-SqlClone command without using "Location" parameter. This usage, will return all clones with specified clone name regardless of location. If there is no clone with specified name, there will be no error message and you will receive null object.
Best Regards
Add comment
Please sign in to leave a comment.
Get-SqlClone -Name $TargetDatabaseName -Location $SqlServerInstance | Remove-SqlClone | Wait-SqlCloneOperation
Because the clone doesn't exists, it can't delete it. I though the logical thing to do would be to wrap this in a statement to check that it has a clone before deleting, but the actual Get-SqlClone is throwing the error because it doesn't exist:
$CloneToDelete = Get-SqlClone -Name $TargetDatabaseName -Location $SqlServerInstance
if ($CloneToDelete)
{
$CloneToDelete | Remove-SqlClone | Wait-SqlCloneOperation
}
Is there a nice way of checking if a clone exists without throwing an error which breaks our deployment step? I'd rather not have to add try...catch blocks into the PowerShell as this isn't really an error and just means we should be able to move onto the clone part of the script if there is no clone to delete first:
$Image | New-SqlClone -Name $TargetDatabaseName -Location $SqlServerInstance | Wait-SqlCloneOperation
Thanks