VBScript to backup and timestamp an Analysis Services Database

This script will backup and Analysis Services 2000 database and timestamp the .cab file with the date of the backup.

Copy and Paste the following script into a file called OlapBackup.vbs and execute it be running the following from a command line.

cscript OlapBackup.vbs

Before running this script in your environment, be sure to update the assignments section.

'----------------------------------------------------------------------------------------------
' Name       : OlapBackup.vbs
' Author     : Darren Gosbell (DPG)
' Date       : 2 Oct 2005
' Description: Generate a command that is used to backup the specified OLAP
'              database ,timestamping the resulting .cab file
'
' Notes      : Before using in new environments you must setup the server
'              name and path variables in the "Assignments" section.
'
'              This script must be run under a user account that is a
'              member of the "OLAP Administrators" group.
'
' Author:  
' Creation Date: 2 Oct 2005
'
' Revision History:
' Date   By Ref# Description
' 02 Oct 2005 DPG N/A  Initial Version
'----------------------------------------------------------------------------------------------
 ' Constants.
 Const vQUOTE = """"
  
 Dim vBackupExe
 Dim vOLAPServer
 Dim vOLAPDataPath
 Dim vOLAPDatabase
 Dim vBackupPath
 Dim vBackupOLAPDbBatchFile
 
 ' Assignments. - THIS SECTION MUST BE UPDATED INORDER TO RUN THIS SCRIPT ON A DIFFERENT SERVER
 ' Note: Do not include embedded double quotes, these are automatically added below.
 vBackupExe = "\program files\microsoft analysis services\bin\msmdarch.exe"
 vOLAPServer = "darren01"
 vOLAPDatabase = "FoodMart 2000"
 vOLAPDataPath = "c:\data\olap"
 vBackupPath = "c:\data\backup"
 
 Dim vNow
 Dim vMthStr
 Dim vDayStr
 Dim vDateStr
 Dim vHourStr
 Dim vMinuteStr
 Dim vBackupFilePath
 Dim vLogFilePath
 Dim vCmd
 
 '\\ Create Timestamp
 vNow = Now()
 vMthStr = CStr(Month(vNow))
 vDayStr = CStr(Day(vNow))
 vHourStr = CStr(Hour(vNow))
 vMinuteStr = CStr(Minute(vNow))
 ' Add leading zeroes to month, day, hour, minutes
 If Len(vMthStr) = 1 Then
    vMthStr = "0" & vMthStr
 End If
 If Len(vDayStr) = 1 Then
    vDayStr = "0" & vDayStr
 End If
 If Len(vHourStr) = 1 Then
    vHourStr = "0" & vHourStr
 End If
 If Len(vMinuteStr) = 1 Then
    vMinuteStr = "0" & vMinuteStr
 End If
 ' Get date string in yyyymmddhhnn format.
 vDateStr = Year(vNow) & vMthStr & vDayStr & vHourStr & vMinuteStr

 ' Set backup and log file path.
 vBackupFilePath = vBackupPath & "\" & vOLAPDatabase & "_olapdb_" & vDateStr & ".cab"
 vLogFilePath = vBackupPath & "\" & vOLAPDatabase & "_olapdb_" & vDateStr & ".log"
 
 ' Construct the msmdarch command line to backup an OLAP database.
 vCmd = vQUOTE & vBackupExe & vQUOTE & " /a " _
  & vQUOTE & vOLAPServer & vQUOTE _
  & " " & vQUOTE & vOLAPDataPath & vQUOTE _
  & " " & vQUOTE & vOLAPDatabase & vQUOTE _
  & " " & vQUOTE & vBackupFilePath & vQUOTE _
  & " " & vQUOTE & vLogFilePath & vQUOTE

 Dim objShell, iReturn
 set objShell = wscript.createObject("wscript.shell")
 iReturn = objShell.Run(vCmd, 1, TRUE)

Print | posted on Sunday, October 2, 2005 6:14 PM

Comments on this post

# re: VBScript to backup and timestamp an Analysis Services Database

Requesting Gravatar...
Quite inspiring,

This is an extermely helpful article,

Keep up the good work,

Thanks for sharing
Left by web development company on Oct 20, 2009 8:39 PM

Your comment:

 (will show your gravatar)