0

I use Automation Runbook to create the Azure Files' snapshot. And I get one error

Exception calling "Snapshot" with "0" argument(s): "The remote server returned an error: (409) Conflict." At line:3 char:1 + $snapshot = $share.Snapshot() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : StorageException,

but it was not consistent.

I use the runbook to create the Azure Files snapshots. At first, it can work well, but recently there have some errors of "The remote server returned an error: (409) Conflict."

I use the code as below to create the snapshots everyday.

$context = New-AzureStorageContext -StorageAccountName "storage" -StorageAccountKey "********"
$share = Get-AzureStorageShare -Context $context -Name "test"
$snapshot = $share.Snapshot()

I want to fix the error.

Exception calling "Snapshot" with "0" argument(s): "The remote server returned an error: (409) Conflict." At line:3 char:1 + $snapshot = $share.Snapshot() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : StorageException

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
Arthur
  • 103
  • 11
  • 1
    Try updating the AzureStorage and dependent modules from Modules Gallery under your Automation Account. Modules Gallery > Search for Module > Import. – tush4r Jul 31 '19 at 09:15
  • Thanks for your comment, I had checked the Azure Storage module Version (4.6.1) and found it is the newest one. Can you show me more information of the dependent modules? – Arthur Aug 01 '19 at 01:55
  • 1
    Could you please confirm if you are doing any of these following 409s https://learn.microsoft.com/en-us/rest/api/storageservices/blob-service-error-codes – tush4r Aug 01 '19 at 02:59
  • @Arthur, just for testing purpose, can you please write a new runbook, and create a new file share, then check if it can work? and also please test it from your pc to see if it works. – Ivan Glasenberg Aug 01 '19 at 08:25
  • By the way, I am running some Runbooks at the same time, will it have some effect on the performance. And sometimes when I met the error, the snapshot can be created successfully. – Arthur Aug 01 '19 at 08:28
  • @IvanYang I have tried wrote a new runbook and create a new file share, it can work well. I think maybe there have some problems with Azure or schedules. – Arthur Aug 01 '19 at 08:35
  • @Arthur, as per the testing, maybe you're right. Its a little difficult to debug for such issues. Do you still need to use that file share? – Ivan Glasenberg Aug 01 '19 at 08:39
  • @IvanYang Yes, I use the Runbook to create daily/monthly snapshot and delete snapshots after one week/two months. – Arthur Aug 01 '19 at 08:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197337/discussion-between-ivan-yang-and-arthur). – Ivan Glasenberg Aug 01 '19 at 09:44
  • @IvanYang Hi, Ivan. Do you know how to link the alert with the Azure Automation together? For example, when I got this error, the runbook which creates a snapshot will run again. Thanks so much. – Arthur Aug 06 '19 at 01:52
  • 1
    @Arthur, why not just use try-catch in runbook? if an error throws, just create it again? – Ivan Glasenberg Aug 06 '19 at 02:50
  • @IvanYang I am sorry I don't know it before. So I just need to update my Runbook code like below: `$RetryIntervalInSeconds = 10` `$NumberOfRetryAttempts = 2` `$CmdOk = $False` `do{ try{ *the code I using now` `$CmdOk = $True}` `catch{ * the error I met ` `$NumberOfRetryAttempts-- Start-Sleep -Seconds $RetryIntervalInSeconds }` `} while (-not $CmdOk -and $NumberOfRetryAttempts -ge 0)`. Is it right? – Arthur Aug 06 '19 at 04:36
  • @Arthur, your code looks right. – Ivan Glasenberg Aug 06 '19 at 06:18

1 Answers1

1

As per discussed with Arthur, we try to use try-catch as a workaround since we didnot figure out the root cause.

when the create snapshot operation fails, then we can retry more times(like 3 times). The sample code like below:

$RetryIntervalInSeconds = 10 
$NumberOfRetryAttempts = 2 
$CmdOk = $False 
do{ 
try{ *the code I using now $CmdOk = $True} 
catch{ * the error I met $NumberOfRetryAttempts-- Start-Sleep -Seconds $RetryIntervalInSeconds } 
} 
while (-not $CmdOk -and $NumberOfRetryAttempts -ge 0)
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • @Fennec @Ivan Yang Hi, sorry for the later replay. I updated the Azure Modules and tested it for about two weeks. It can work well. The error may be occurred by the old PowerShell version. So I installed the new PowerShell module:**Az.Storage **and dependent module **Az.Accounts. ** Then updated the codes as below: `$context = New-AzStorageContext -StorageAccountName "storage" -StorageAccountKey "********" $share = Get-AzStorageShare -Context $context -Name "test" $snapshot = $share.Snapshot()` – Arthur Aug 20 '19 at 04:48
  • @Arthur, that's good. We're using az module now, but not thought that would be an issue in the old module azureRm. Thanks for your sharing. – Ivan Glasenberg Aug 20 '19 at 05:16