我使用Azure CLI将备份备份资源组中的数据库导出到blobstorage,所以我想在python script上使用相同的命令。
例如,我在Azure CLI中使用以下命令来导出资源组中的数据库:
az sql db export -s (sql server) -n (database) -g (group) -p (password)
-u login --storage-key " key "
--storage-key-type
--storage-uri (url blob)
如何使用Python脚本来实现这一目标?
您可以使用Python中的REST API将Azure SQL数据库导出为bacpac。
这是一个示例请求。
POST https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-4799/providers/Microsoft.Sql/servers/sqlcrudtest-5961/databases/testdb/export?api-version=2014-04-01
请求正文。
{
"storageKeyType": "SharedAccessKey",
"storageKey": "?sr=b&sp=rw&se=2018-01-01T00%3A00%3A00Z&sig=sdfsdfklsdjflSLIFJLSIEJFLKSDJFDd/%2wdfskdjf3%3D&sv=2015-07-08",
"storageUri": "https://test.blob.core.windows.net/bacpacs/testbacpac.bacpac",
"administratorLogin": "dummyLogin",
"administratorLoginPassword": "Un53cuRE!",
"authenticationType": "SQL"
}
示例响应。
{
"id": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/sqlcrudtest-4799/providers/Microsoft.Sql/servers/sqlcrudtest-5961/importExportOperationResult/f01d7bfe-7162-44e7-9350-f1c85ce83e4c",
"name": "f01d7bfe-7162-44e7-9350-f1c85ce83e4c",
"type": "Microsoft.Sql/servers/importExportOperationResults",
"properties": {
"requestId": "f01d7bfe-7162-44e7-9350-f1c85ce83e4c",
"requestType": "Export",
"queuedTime": "3/1/2017 12:14:25 AM",
"lastModifiedTime": "3/1/2017 12:16:33 AM",
"blobUri": "https://test.blob.core.windows.net/bacpacs/test.bacpac",
"serverName": "test",
"databaseName": "testdb",
"status": "Completed",
"errorMessage": null
}
}