【问题标题】:SQL Azure rest api BeginExport... how to check if export completedSQL Azure rest api BeginExport ...如何检查导出是否完成
【发布时间】:2017-09-21 14:01:06
【问题描述】:

我需要以编程方式将 SQL Azure 数据库导出到 BACPAC 文件,导出完成后我需要删除数据库。

SQL Azure REST API 允许我提交导出请求,该请求将运行并将数据库导出到 blob 存储容器。

但是...我看不到如何检查导出请求的状态。

导出 api 说明如下:https://docs.microsoft.com/en-us/rest/api/sql/Databases%20-%20Import%20Export/Export

以及整体SQL api描述:https://docs.microsoft.com/en-us/rest/api/sql/

【问题讨论】:

    标签: sql azure azure-sql-database


    【解决方案1】:

    sys.dm_ operation_status DMV 应该可以帮助您了解操作的状态。

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

    有关此 DMV 的更多信息,请访问 this 文档。

    如果您使用 PowerShell New-Azure​RmSql​Database​Export cmdlet,您可以使用 Get-AzureRmSqlDatabaseImportExportStatus cmdlet 来跟踪导出操作和导入操作的进度。

    【讨论】:

    • 不。该视图不包括 Azure 导出任务。
    • 我需要做同样的事情,除了我需要检查导入的状态,而不是导出的状态。这有什么好运气吗?
    • @ColinLaws 如果您使用 PowerShell New-AzureRmSqlDatabaseImport 那么您可以使用 Get-AzureRmSqlDatabaseImportExportStatus 来跟踪导入操作。
    【解决方案2】:

    对于任何 api 如 BeginX(),都有一个对应的 api X() 等待完成。在这种情况下,请使用 Export() 而不是 BeginExport()

    如果您希望更直接地控制轮询,那么您可以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);
            }
    

    此答案专门针对 .net,但对于其他语言,同样的原则也适用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 2013-02-08
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2018-02-03
      相关资源
      最近更新 更多