2

I'm trying to monitor an ongoing database copy, (Start-AzureSqlDatabaseCopy). I've set up the following:

$dbCopy = Start-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseName $sourceDbName -PartnerDatabase $targetDbName -PartnerServer $serverName

WHILE ($dbCopy)
{
   $dbCopy = Get-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseCopy $dbCopy
   Write-Host $dbCopy.ReplicationStateDescription
   [System.Threading.Thread]::Sleep(1000);
}

The state is pending (the first approx. 7 times) and then returns an exception of "resource does not exist". The database gets copied ok, but how do I monitor with script?'

This is where I got the general outline of the approach (https://stackoverflow.com/a/25268033/4261741)

6
  • 1
    Is that just what gets returned once the copy is finished? Or do you actually get a completed ReplicationStateDescription eventually? Commented Nov 17, 2014 at 15:46
  • In the while-loop, I get back a complete DataBaseCopy object with ReplicationStateDescription PENDING several times. It seems like when the status changes, I get this exception. Commented Nov 17, 2014 at 17:32
  • Yes but do you get the exception because it finished? If the copy has completed it seems reasonable that calling a Get-AzureSqlDatabaseCopy command might fail as the copy process doesn't exist any more Commented Nov 17, 2014 at 17:34
  • Yes, that's probably so. But I need to monitor when the jobs done without having try/catch handle an exception since I get the same exception if something is actually wrong. Commented Nov 17, 2014 at 17:39
  • So just add the try/catch around that single statement and examine the message property. If it's not resource does not exist then re-throw or handle some other way. Commented Nov 17, 2014 at 17:41

2 Answers 2

1

You can check the percentage as below.

Start-AzureSqlDatabaseCopy -ServerName $SourceServerName -DatabaseName $SourceDatabaseName -PartnerServer $TargetServerName -PartnerDatabase $TargetDatabaseName 

$i = 0

do
{
    sleep -Seconds 5
    $check = Get-AzureSqlDatabaseCopy -ServerName $TargetServerName -DatabaseName $TargetDatabaseName
    $i = $check.PercentComplete
}
while ($i -ne $null)
Sign up to request clarification or add additional context in comments.

Comments

0

In case anyone else comes back to this answer, if you use the new resource manager cmdlet, then you don't need to monitor progress. It blocks until the copy is complete. New-AzureRmSqlDatabaseCopy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.