[英]How to restore schema on the Azure SQL Server Databases using PowerShell script?
我已經創建了一個 sql 服務器,在該服務器上部署了彈性池,並且能夠按照此鏈接https://dba.stackexchange.com/a/257739/197860在該彈性池中創建多個數據庫。 現在我上傳這個問題的目的是..我只想恢復架構,然后使用 PowerShell 腳本將數據恢復到那些創建的 azure sql 數據庫。 任何人都可以幫我解決這個問題嗎?
如果您想將架構從本地 SQL 服務器還原到彈性池中的 Azure SQL 數據庫,您可以使用工具數據遷移助手(DMA) 。
DMA 支持 oly 遷移模式:
如果要還原 Azure SQL 數據庫之間的架構,可以使用 SSMS 生成和發布腳本向導。 可以使用生成和發布腳本向導創建腳本,以便在 SQL Server 數據庫引擎或 Azure SQL 數據庫的實例之間傳輸數據庫。
右鍵單擊數據庫--生成腳本:
然后你可以使用 PowerShell 來運行 SQL 腳本。
參考:
我有一個問題,既然您需要將架構和稍后的數據恢復到那些創建的 Azure SQL 數據庫,為什么不導入備份文件(如 .bacpac 文件)以直接使用 PowerShell 在該 Azure SQL 服務器中創建數據庫?
請參考這些教程:
希望這可以幫助。
還原 bacpac 會在 Azure SQL 數據庫上創建一個新數據庫。 下面是 PowerShell 腳本來恢復它。
# Restore/Import bacpac to database with an S3 performance level
$importRequest = New-AzSqlDatabaseImport -ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $databaseName `
-DatabaseMaxSizeBytes "262144000" `
-StorageKeyType "StorageAccessKey" `
-StorageKey $(Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName).Value[0] `
-StorageUri "https://$storageaccountname.blob.core.windows.net/$storageContainerName/$bacpacFilename" `
-Edition "Standard" `
-ServiceObjectiveName "S3" `
-AdministratorLogin "$adminSqlLogin" `
-AdministratorLoginPassword $(ConvertTo-SecureString -String $password -AsPlainText -Force)
# Check restore/import status and wait for the import to complete
$importStatus = Get-AzSqlDatabaseImportExportStatus -OperationStatusLink $importRequest.OperationStatusLink
[Console]::Write("Importing")
while ($importStatus.Status -eq "InProgress")
{
$importStatus = Get-AzSqlDatabaseImportExportStatus -OperationStatusLink $importRequest.OperationStatusLink
[Console]::Write(".")
Start-Sleep -s 10
}
[Console]::WriteLine("")
$importStatus
恢復后,您可以將數據庫分配給彈性池。
# Move the database to the pool
$firstDatabase = Set-AzSqlDatabase -ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $firstDatabaseName `
-ElasticPoolName $PoolName
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.