patternMinor
Script out XMLA for all databases
Viewed 0 times
scriptxmladatabasesallforout
Problem
I have several SSAS databases. I only want to script out the XMLA for them on a nightly basis. This will be a second tier backup in addition to the regular backups we have.
How do I auto-generate XMLA scripts for all the databases?
How do I auto-generate XMLA scripts for all the databases?
Solution
You can do it using powershell.
References :
$serverName = "servername\instanceName"
$outputFolder = "D:\data\"
## load the AMO and XML assemblies into the current runspace
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") > $null
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml") > $null
$dateStamp = (get-Date).ToString("yyyyMMdd")
## connect to the server
$svr = new-Object Microsoft.AnalysisServices.Server
$svr.Connect($serverName)
foreach ($db in $svr.Databases)
{
write-Host "Scripting: " $db.Name
$xw = new-object System.Xml.XmlTextWriter("$($outputFolder)DBScript_$($db.Name)_$($dateStamp).xmla", [System.Text.Encoding]::UTF8)
$xw.Formatting = [System.Xml.Formatting]::Indented
[Microsoft.AnalysisServices.Scripter]::WriteCreate($xw,$svr,$db,$true,$true)
$xw.Close()
}
$svr.Disconnect()References :
- Automating the Scripting of an SSAS database
- PowerShell to Script SQL Analysis Service Database(XMLA Script) and ReApply on a different Server
- SQL Server Analysis Services Backup in Powershell
Code Snippets
$serverName = "servername\instanceName"
$outputFolder = "D:\data\"
## load the AMO and XML assemblies into the current runspace
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") > $null
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml") > $null
$dateStamp = (get-Date).ToString("yyyyMMdd")
## connect to the server
$svr = new-Object Microsoft.AnalysisServices.Server
$svr.Connect($serverName)
foreach ($db in $svr.Databases)
{
write-Host "Scripting: " $db.Name
$xw = new-object System.Xml.XmlTextWriter("$($outputFolder)DBScript_$($db.Name)_$($dateStamp).xmla", [System.Text.Encoding]::UTF8)
$xw.Formatting = [System.Xml.Formatting]::Indented
[Microsoft.AnalysisServices.Scripter]::WriteCreate($xw,$svr,$db,$true,$true)
$xw.Close()
}
$svr.Disconnect()Context
StackExchange Database Administrators Q#51129, answer score: 4
Revisions (0)
No revisions yet.