Search code examples
azure-powershellazure-analysis-services

Azure Analysis Services database model backups using powershell or azure cli


I'm trying to take backups of AAS databse models using below powershell script. I'm finding hard since there is no good Microsoft documentation around to implement this solution.

$AnalysisServiceDatabase = "adventureworks"
$AnalysisServiceServer = "testanalysis"
$automationConnectionName = $ConnectionName 
if (!$ConnectionName) { 
    $automationConnectionName = "AzureRunAsConnection" 
}  
$servicePrincipalConnection = Get-AutomationConnection -Name $automationConnectionName          

Write-Output "Logging in to Azure..." 
 
Add-AzureRmAccount `
    -ServicePrincipal `
    -TenantId $servicePrincipalConnection.TenantId `
    -ApplicationId $servicePrincipalConnection.ApplicationId `
    -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint

# Get PSCredential 
$cred = Get-AutomationPSCredential -Name $AutomationCredentialName

Write-Output "Starting Backup..." 

Backup-ASDatabase `
    –backupfile ("backup." + (Get-Date).ToString("yyMMdd") + ".abf") `
    –name $AnalysisServiceDatabase `
    -server $AnalysisServiceServer `
    -Credential $cred

Could anyone help me? If there any alternative way to take automatic backups of azure analysis services databases?


Solution

  • There are, I’m sure, several approaches to this. Your script is pretty close. If you change the backup command as follows I suspect it will work:

    
    Backup-ASDatabase `
        –backupfile ("backup." + (Get-Date).ToString("yyMMdd") + ".abf") `
        –name $AnalysisServiceDatabase `
        -server "asazure://<full server URI here>" `
          -ApplyCompression `
          -ServicePrincipal `
          -ApplicationId $servicePrincipalConnection.ApplicationId `
          -TenantId $servicePrincipalConnection.TenantId `
          -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
    
    
    
    

    If you need more features like resuming the server and opening the firewall to the current Azure Automation public IP temporarily then do the following instead. Hopefully you can piece together the script you want from two examples.

    First create a runbook from this script (which processes an Azure Analysis Services database). Note the setup instructions here.

    Then replace lines 100-123 with the backup database code from this script (which backs up on prem and restores to Azure Analysis Services) from lines 162-215. And change $Server to $amoAzureASServer.