Met dit script kun je een backup maken van de Azure SQL databases. Onderstaand script is gemaakt voor een Octopus deploy. Octopus Deploy is een tool voor het geautomatiseerd deployen van software.
Pas de variabele aan met de juiste gegevens.
$ResourceGroupName = $OctopusParameters[‘ResourceGroupName’]
$SqlServerName = $OctopusParameters[‘SqlServerName’]
$SqlServerPassword = $OctopusParameters[‘SqlServerPassword’]
$SqlServerUser = $OctopusParameters[‘SqlServerUser’]
$StorageAccount = $OctopusParameters[‘StorageAccount’]
$StorageKey = $OctopusParameters[‘StorageKey’]
$StorageKeytype = $OctopusParameters[‘StorageAccessKey’]
$StorageContainerName = $OctopusParameters[‘StorageContainerName’]
$BacpacUri = $OctopusParameters[‘BacpacUri’]
$DatabaseName = $OctopusParameters[‘DatabaseName’]
# Check if Windows Azure Powershell is avaiable
try{
Import-Module Azure -ErrorAction Stop
}catch{
throw “Windows Azure Powershell not found! Please make sure to install them from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools”
}
$dateTime = get-date -Format “_yyyyMMd_HHmmss”
$blobName = “Deployment-Backup/Database/$DatabaseName$dateTime.bacpac”
Write-Host “Using blobName: $blobName”
# Create Database Connection
$securedPassword = ConvertTo-SecureString -String $SqlServerPassword -asPlainText -Force
$serverCredential = new-object System.Management.Automation.PSCredential($SqlServerUser, $securedPassword)
#$databaseContext = New-AzureSqlDatabaseServerContext -ServerName $SqlServerName -Credential $serverCredential
# Create Storage Connection
#$storageContext = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageKey
#Initiate the Export
#Start-AzureSqlDatabaseExport -StorageContext $storageContext -SqlConnectionContext $databaseContext -BlobName $blobName -DatabaseName $DatabaseName -StorageContainerName $StorageContainerName
$exportRequest = New-AzureRmSqlDatabaseExport –ResourceGroupName $ResourceGroupName –ServerName $SqlServerName `
–DatabaseName $DatabaseName –StorageKeytype $StorageKeytype –StorageKey $StorageKey -StorageUri $BacpacUri/$blobName `
–AdministratorLogin $SqlServerUser –AdministratorLoginPassword $securedPassword
# Check status of the export
Start-Sleep -s 10
for($counter = 1; $counter -le 10; $counter++)
{
Start-Sleep -s 10
Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink
“Loop number $counter”
}
#Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink