SQL Azure rest api BeginExport… how to check if export completed

自闭症网瘾萝莉.ら 提交于 2019-12-24 09:55:26

问题


I need to programmatically export an SQL Azure database to a BACPAC file and once the export has completed I need to delete the database.

The SQL Azure REST API allows me to submit an export request which will run and export the database to a blob storage container.

But... I can't see how to check on the status of the export request.

Here's the export api description: https://docs.microsoft.com/en-us/rest/api/sql/Databases%20-%20Import%20Export/Export

And the overall SQL api description: https://docs.microsoft.com/en-us/rest/api/sql/


回答1:


The sys.dm_ operation_status DMV should help you know the status of the operation.

SELECT * FROM sys.dm_ operation_status   
   WHERE major_resource_id = ‘myddb’   
   ORDER BY start_time DESC;

For more inromation about this DMV, please visit this documentation.

If you use PowerShell New-Azure​RmSql​Database​Export cmdlet you can use Get-AzureRmSqlDatabaseImportExportStatus cmdlet to track the progress of an export operation and of an import operation too.




回答2:


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

If you wish to have more direct control over the polling, then you can look inside the definition of Export and directly use the lower layer:

        public async Task<AzureOperationResponse<ImportExportResponse>> ExportWithHttpMessagesAsync(string resourceGroupName, string serverName, string databaseName, ExportRequest parameters, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Send request
            AzureOperationResponse<ImportExportResponse> _response = await BeginExportWithHttpMessagesAsync(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.



来源:https://stackoverflow.com/questions/46346009/sql-azure-rest-api-beginexport-how-to-check-if-export-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!