使用PowerShell脚本的Azure SQL备份自动化

问题描述 投票:0回答:1

我正在编写一个代码,使用PowerShell脚本在Blob存储上进行Azure SQL备份。当我运行脚本时,它正在显示正在进行但是在我检查blob容器的一段时间后我无法看到任何.bacpac(备份)文件。当我试图在一段时间后再次运行代码时,它会显示如下enter image description here的错误

但是一段时间后,当我再次运行我的代码时,它正在成功执行,状态将显示“正在进行中”。但是当我在blob容器下检查时,将没有文件。请在下面找到脚本 -

$subscriptionId = "*****"
$serverAdmin = '****'
$serverPassword = '****'
$securePassword    = ConvertTo-SecureString $serverPassword -AsPlainText -Force
$creds           = New-Object System.Management.Automation.PSCredential($serverAdmin, $securePassword)
$DatabaseName ='*****'
$ResourceGroupName='*****'
$ServerName='*****'

# Generate a unique filename for the BACPAC
$bacpacFilename = $DatabaseName + (Get-Date).ToString("yyyyMMddHHmm") + ".bacpac"

# Storage account info for the BACPAC
$BaseStorageUri = "https://*****.blob.core.windows.net/*****"
$BacpacUri = $BaseStorageUri + $bacpacFilename
$StorageKeytype = "StorageAccessKey"
$StorageKey = "*****"

New-AzureRmSqlDatabaseExport -ResourceGroupName $ResourceGroupName -ServerName $ServerName `
   -DatabaseName $DatabaseName -StorageKeytype $StorageKeytype -StorageKey $StorageKey -StorageUri $BacpacUri `
   -AdministratorLogin $creds.UserName -AdministratorLoginPassword $creds.Password
powershell azure-devops azure-sql-database azure-storage
1个回答
0
投票

我有一个问题,请查看您的代码:enter image description here

为什么这些代码-DatabaseName $DatabaseName -StorageKeytype $StorageKeytype -StorageKey $StorageKey -StorageUri $BacpacUriString

然后执行New-AzureRmSqlDatabaseExport肯定会出错。你可以看到这个文件:New-AzureRmSqlDatabaseExport

关于另一个错误:

Error encountered during the service operation. Blob https://****.blob.core.windows.net/*** is not writeable. The remote server returned an error: (404) Not Found. The remote server returned an error: (404) Not Found

我想你可以看到这个blob作为参考:Blob is not writeable。这个blob有和你一样的错误:

Error encountered during the service operation. Blob https://XXXXXXXXXX.blob.core.windows.net/XXXXX-container/ABC.bacpacklj1234klj12l3k4jl2k34jl2k3j4lk23j4l12k34jlk23j4lk23lk4j234A8i3t1GAs4Tvx2wjQRf7nTi/fM0+v7o7SWuUTU6WpRwO2SM0w== is not writeable. The remote server returned an error: (404) Not Found. The remote server returned an error: (404) Not Found.

它最终起作用:enter image description here

希望这可以帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.