Azure / Azure/azure-powershell
Get-AzSqlDatabaseImportExportStatus SAS token expires for long running import or export jobs in Azure Powershell Runbook
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
## Description
After initiating an import or export using New-AzSqlDatabaseImport or New-AzSqlDatabaseExport and then using Get-AzSqlDatabaseImportExportStatus to monitor progress, if the process takes more than 1 hour then calls to Get-AzSqlDatabaseImportExportStatus fail with the message "Get-AzSqlDatabaseImportExportStatus : ExpiredAuthenticationToken: The access token expiry UTC time '10/25/2020 10:51:41 AM' is earlier than current UTC time '10/25/2020 10:52:13 AM'". The AzureRM modules do not suffer the same problem and continue polling until completion.
## Steps to reproduce
```powershell
$importrequest = New-AzSqlDatabaseImport `
-ResourceGroupName "$Using:ResourceGroupName" `
-ServerName "$Using:ServerName" `
-DatabaseName $Using:DatabaseName `
-StorageKeytype "$storageKeytype" `
-StorageKey "$storageKey" `
-StorageUri "$bacpacUri" `
-AdministratorLogin $creds.UserName `
-AdministratorLoginPassword $creds.Password `
-Edition "Standard" `
-ServiceObjectiveName "$Using:RestoreServicePlan" `
-DatabaseMaxSizeBytes 107374182400
$importstatus = Get-AzSqlDatabaseImportExportStatus -OperationStatusLink $importrequest.OperationStatusLink
while (($importstatus.Status -eq "InProgress") -or ($importstatus.Status -eq "Pending")) {
Write-Output "Import status is $($importstatus.Status)"
Start-Sleep -s 300
$importstatus = Get-AzSqlDatabaseImportExportStatus -OperationStatusLink $importrequest.OperationStatusLink
# after 1 hour, this call starts to fail
}
```
## Environment data
```
```
## Module versions
```powershell
Az.Accounts 1.9.5
Az.Resources 2.5.1
Az.Sql 2.9.1
Az.Storage 2.7.0
```
## Debug output
```
```
## Error output
```
```
Contributor guide
Research direction
Start with the New-AzSqlDatabaseImport or New-AzSqlDatabaseExport entry points and the repeated Get-AzSqlDatabaseImportExportStatus call shown in the reproduction. Compare the Az.Sql behavior with AzureRM for operation-status polling and investigate token handling for jobs lasting over one hour. Done means the status loop continues until a long-running import or export completes without an ExpiredAuthenticationToken failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- cloud, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100