5

I am performing a SQL Database Import using a BacPac file to Azure using the REST management API. I need to be able to check the status of an import, as Azure does not allow for me to send events when the import succeeds.

Here is the documentation for the operation I am performing: https://learn.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export/import

I have already tried using the Azure's Analysis Services API to check an operation's status by the operation id and the region it occurred in. Calling this endpoint however is returning me a 404 not found.

Here is the documentation for Azure's Analysis Services API endpoint I am attempting to call with my import's operation id and the region it occurred in: https://learn.microsoft.com/en-us/rest/api/analysisservices/servers/listoperationresults

I am expecting the Analysis Services to provide me with the status of an import/export operation I started using the Azure Management API. Doing so is resulting in a 404, so I'm not sure if I'm calling the correct API endpoint (I double checked to make sure there are no typos in the URI I am building to check the operation status).

Colin
  • 624
  • 8
  • 27
  • Just as a side note, I am aware that a similar answer was posted for the following question; however, it does not provide a solution to this issue: https://stackoverflow.com/questions/46346009/sql-azure-rest-api-beginexport-how-to-check-if-export-completed – Colin Jun 20 '19 at 19:09
  • did you manage to get the status without powershell? – rfcdejong Sep 18 '20 at 15:25

6 Answers6

5

in the database go to overview -> in the bottom check notifications -> you do make click in tha image

enter image description here

enter image description here

Vesper
  • 375
  • 1
  • 8
  • 14
  • The question specifies that I am trying to obtain the status via the Azure ARM REST API. – Colin Jun 28 '21 at 14:35
2

I do know how to track the progress of an import/export operation if you use PowerShell instead but I don't know a way to track the progress using Azure REST API.

If you use PowerShell New-AzureRmSqlDatabaseImport cmdlet to import a database or you use New-Azure​RmSql​Database​Export to export a database then you can use Get-AzureRmSqlDatabaseImportExportStatus to track the progress of the import/export operation.

Alberto Morillo
  • 13,893
  • 2
  • 24
  • 30
  • My project requires that I be able to import databases to Azure SQL via the REST API, as well as check the status of an import through the API as well. I am currently working with Microsoft on finding a solution, and they did offer the powershell approach; however, like I mentioned, this unfortunately wont work for my use case. – Colin Jun 21 '19 at 12:43
  • 1
    One way you can consume PowerShell in this case without directly executing the commands from a web app is by creating an Azure Function app with PoweShell Core. Simply write functions to wrap PowerShell commands you want to consume, and call them with an Http client. – Colin Apr 24 '20 at 02:46
  • 1
    @Alberto - AzureRmSqlDatabaseImportExportStatus, and it's current version Az.Sql.Get-AzSqlDatabaseImportExportStatus both expect an OperationStatusLink parameter which is typically returned by the cmdlet that initiates the export. How do you get the OperationStatusLink for an export which was initiated by let's say the Azure portal, and you want to check the status? – Matthew Oct 02 '20 at 00:18
1

For any api such as BeginX(), there is a corresponding api X() which waits for completion. In this case, instead of BeginImport() use Import().

If you wish to have more direct control over the polling, then you can look inside the definition of Import and directly use the lower layer, i.e. BeginImportWithHttpMessagesAsync() and then GetPostOrDeleteOperationResultAsync():

        public async Task<AzureOperationResponse<ImportExportResponse>> ImportWithHttpMessagesAsync(string resourceGroupName, string serverName, string databaseName, ExportRequest parameters, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Send request
            AzureOperationResponse<ImportExportResponse> _response = await BeginImportWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters, customHeaders, cancellationToken).ConfigureAwait(false);

            // Poll for completion
            return await Client.GetPostOrDeleteOperationResultAsync(_response, customHeaders, cancellationToken).ConfigureAwait(false);
        }

This answer is specifically for .net but for other languages the same principle applies.

Jared Moore
  • 3,765
  • 26
  • 31
  • I am using PHP, and Microsoft does not provide a client library for this language. Is there a way to do this through the REST API? – Colin Jun 24 '19 at 10:48
  • 1
    Yes, the code that I am referring to is just a layer above the REST API. The POST response will contain Location header which specified the operation status URI. You can GET that URI to check the progress. The URI that Location header returns is deliberately not documented in Swagger because it should be opaque to clients, i.e. clients should have no expectation of what the path should be. – Jared Moore Jul 12 '19 at 00:04
  • Unfortunately I found out that while it is possible to check the status, you can't differentiate between the status of 'succeeded' and 'failed', as the import operation status URI contains the name of the database being imported in its path. Which means if the import fails, the URI will return a 404 (because the database would have never been created, therefore the path does not point to a real resource). – Colin Jul 12 '19 at 19:37
1

To monitor import's progress, open the database's server page, and, under Settings, select Import/Export history. When successful, the import has a Completed status.

https://learn.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-import?view=azureipps&tabs=azure-powershell

miraba
  • 21
  • 4
  • I have specified in my original post that I am using the Azure REST API to check this information. – Colin Jan 21 '20 at 20:31
0

I find an article Azure SQL Database Export, it talked about how to check the status of an export by using the Microsoft Azure SQL Database Import/Export REST service API.

Summary:

In the Management Portal, click on the database and the dashboard will show you the recent export status. In Screenshot 5, you will see that the AUTOMATED EXPORT status for my database shows as NEVER EXPORTED. This will change once a successful export is done. In the Management Portal, click on the database and the dashboard will show you the recent export status. enter image description here

After the export completes which was ultimately scheduled at 1AM, completed after 5 minutes and the automated export status in my dashboard shows that the same. (See screenshot 6). enter image description here

Hope this helps.

Community
  • 1
  • 1
Leon Yue
  • 15,693
  • 1
  • 11
  • 23
  • Unfortunately this does not help. This article shows the use of the legacy Azure portal, and does not offer an example of accessing an import's status via the Azure Resource Manager API. – Colin Jun 21 '19 at 12:41
0

According to Microsoft:

"We have REST API’s for Import/Export operations into Azure sql but we don’t have any REST API to find Import/Export status. Customer should use Powershell to get status"

I also discovered that it is not possible to know if an import failed using the Powershell command, because it doesn't have a database uri (because the import failed) to hit for checking the import status.

Colin
  • 624
  • 8
  • 27