Report Portal

About me

I work as SQL Server DBA / Developer and BI Consultant in Toronto, Canada.Canada Flag More...
Vidas Matelis picture

Search

blank

Script to backup Analysis Services 2005 databases

July 26th, 2007 by Vidas Matelis

Recently I was asked for a generic script that does backup of all Analysis Services 2005 databases on one server.

 I quickly wrote SSIS package that does just that. You can download this package from here.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain
    Public Sub Main()
        Dim sSSASServerName As String = CStr(Dts.Variables(“SSASServerName”).Value)
        Dim sBackupLocation As String = CStr(Dts.Variables(“BackupLocation”).Value)
        If Right(sBackupLocation, 1) <> “\” Then sBackupLocation = sBackupLocation + “\”

        Dim Locations() As Microsoft.AnalysisServices.BackupLocation
        Dim oServer As New Microsoft.AnalysisServices.Server
        oServer.Connect(sSSASServerName) ‘ connect to the server and start scanning down the object hierarchy
        Dim oDB As Microsoft.AnalysisServices.Database
        For Each oDB In oServer.Databases
            ‘If oDB.Name = “AdventureWords” Then ‘ here you can include or excluded databases
            oDB.Backup(sBackupLocation & oDB.Name & “_” & Now().ToString(“yyyyMMdd_hhmmss”) & “.abf”, True, False, Locations, True)
            ‘End If
        Next
        Dts.TaskResult = Dts.Results.Success
    End Sub
 
End Class

If you wish you can use CaptureXML technique (described in my previous blogs) for doing backups in parallel, but I usually like to leave some server power to users so they can query data while backups are executed. Running multiple database backups in parallel could have huge performance impact for end user querying. 

You can execute this package from command line and pass parameters that specify server name and location:

dtexec /FILE “C:\DTSX_Scripts\DWBackupOLAPDBs.dtsx” /Set \package.variables[BackupLocation].Value;c:\NewBackupLocation\ /Set \package.variables[SSASServerName].Value;NewSSASServerName

When I have to write a script to backup one or a few databases with a known name, then I usualy use XMLA command:

<Backup xmlns=”http://schemas.microsoft.com/analysisservices/2003/engine”>
  <Object>
    <DatabaseID>MyDBName</DatabaseID>
  </Object>
  <File>c:\BackupLocation\MyDBName.abf</File>
</Backup>

 This XMLA script could be executed using one of these methods:

  • SSIS package using control flow item “Analysis Services Execute DDL task”
  • SQL Server Job create step with type “SQL Server Analysis Services command”
  • using ascmd.exe utility.

Posted in SSAS | 17 Comments »

17 Responses

  1. Sean Says:

    Excellent article. I like the ssis approach much better than the AMO csharp examples that MS provides.

  2. Dan Says:

    Vidas, thanks! This is exactly what I was looking for.

  3. Mohammed Imtiaz Says:

    Please send me the project on my email id its very urgetn, I am not able to download the same..
    my mail id is mohd…

  4. santosh Says:

    Please send me the project on my email id its very urgetn, I am not able to download the same..
    my mail id is santosh.patna.net@gmail.com

  5. Richard R Says:

    Hi,
    The Microsoft.AnalysisServices namespace does not seem to be registered on the server I am using, although it has a full installation of SQL/AS 2005 Enterprise on it. Any ideas where I can find the component?

    R.

  6. Sunny Says:

    Hi,

    Can you please send this dtsx package on my email id sunnysqldba@gmail.com?

    Thanks in advance.

    Sunny

  7. Sunny Says:

    Hi Vidas,

    Thanks for your help.

    I have one more query,
    How can we schedule to remove 10 days old these Analysis Services backup files?

    Thanks
    Sunny

  8. BravehearT1326 Says:

    does this script work with SQL 2008?

  9. Vidas Matelis Says:

    Yes, this script will work with SSAS 2008.

  10. BravehearT1326 Says:

    Hi there – can you advise me how I would incorporate a new variable into the script for the day of the week.

    I’d like the backup path to make the backup path something like:

    \\server\share\backups\dayofweek\

    What language is the script also written in as well.

  11. Vidas Matelis Says:

    Hi BravehearT1326,

    This code is written inside SSIS script task and it is using VB.

    You should be looking to update string:
    oDB.Backup(sBackupLocation & oDB.Name & “_” & Now().ToString(“yyyyMMdd_hhmmss”) & “.abf”, True, False, Locations, True)

    Just find in VB how to get name or day of week and then you would write something like this:

    oDB.Backup(sBackupLocation & dayofweek & “\” & oDB.Name & “.abf”, True, False, Locations, True)

  12. BravehearT1326 Says:

    Many thanks for your speedy reply and great script. I will make full use of this.

  13. EJ Says:

    Hi, I use a SQL job to backup the data as per below, but I am receiving an error “Allocation failure : Not enough storage is available to process this command.” some times, we have 24 GB of RAM. Any idea of how to fix it? – thanks.

    DW Analysis Services

    \\Smelpinfxxx\SQLBackups\SMELPSQLxxx\AnalysisServices\DW Analysis Services.abf
    true
    false

  14. Vidas Matelis Says:

    EJ,

    I have not seen case when not enough RAM would affect backup. It is much much more likely that you do not have permission to write to that \\smelpinfxxx share or if you have quote setup on that share that prevents you to write more than x MB of data there. Make sure that SQL Server Agent service account has permission to write to that share as it is used when you run SQL job.

  15. GsusLuyo Says:

    I have the same problem that EJ. I try to backup in the same server (no shared directory). Day before Backup size 1GB but in one day this size increments in a 20 percent (Historical Load has been realized). The Process fail but leave a .abf file with a size similar size to before backup.

    the specific error in SSIS 2008 is
    [Analysis Services Execute DDL Task] Error: Memory error: Allocation failure. I try in SSAS and the same error. Please Notice me, and excuse my poor english.

    Gsus

  16. Pedro Figueiredo Says:

    Thanks, very useful

  17. valerie Says:

    Hello.. I have this script in my SQL Scheduler but it is not parsing. I get when I execute via SQL Agent Job but not when I run in query window where I generated the script. It is complaining on the ‘>’ syntax.any ideas? Valerie