'****************************************
' Description:
' Metabase Backup Utility
' Syntax:
' CSCRIPT MBACKUP.VBS
'****************************************
Option Explicit
On Error Resume Next
' Declare variables.
Dim strBackupName, lngBackupVersion, lngBackupFlags
Dim objComputer
Dim strDay, strMonth, strYear, strComputer
'Get the machine name
Set objComputer = CreateObject("Shell.LocalMachine")
strComputer = objComputer.MachineName
' Get the current DD/MM/YY as strings.
strDay = Right("00" & Cstr(Day(Date())),2)
strMonth = Right("00" & Cstr(Month(Date())),2)
strYear = Cstr(Year(Date()))
' Create a file name from the current date.
strBackupName = strComputer & "_" & strMonth & "-" & strDay & "-" & strYear
' Use the next available version number.
lngBackupVersion = &HFFFFFFFF
lngBackupFlags = 0
' Output the backup message.
'Wscript.Echo "Backing up metabase to file: """ & strBackupName & """"
' Get the ADSI object.
Set objComputer = GetObject("IIS://LOCALHOST")
' Call the backup method.
objComputer.BackupWithPassword strBackupName, lngBackupVersion, lngBackupFlags, "password"
' Check for errors.
'If Err.Number <> 0 Then
' Wscript.Echo "Error: " & Err.Description & " (0x" & Right(String(8,"0") & Hex(Err.Number),8) & ")"
'Else
' Wscript.Echo "Success."
'End If
'****************************************
' The remaining code is optional and deletes a specific older backup.
'****************************************
' The value of lngBackupToDelete determines which specific date to delete
' in this case. 28 days is four weeks ago if you are running a weekly backup.
Const lngBackupToDelete = 28
' Declare variables.
Dim strOldDay, strOldMonth, strOldYear, strOldBackupName
' Get the old DD/MM/YY as strings.
strOldDay = Right("00" & Cstr(Day(Date()-lngBackupToDelete)),2)
strOldMonth = Right("00" & Cstr(Month(Date()-lngBackupToDelete)),2)
strOldYear = Cstr(Year(Date()-lngBackupToDelete))
' Create the file name from the old date.
strOldBackupName = strComputer & "_" & strOldMonth & "-" & strOldDay & "-" & strOldYear
' Output the deletion message.
'Wscript.Echo "Deleting metabase backup file: """ & strOldBackupName & """"
' Call the deletion method.
objComputer.DeleteBackup strOldBackupName, 0
' Check for errors.
'If Err.Number <> 0 Then
' If Err.Number = &H80070002 Then
' Wscript.Echo "File not found."
' Else
' Wscript.Echo "Error: " & Err.Description & " (0x" & Right(String(8,"0") & Hex(Err.Number),8) & ")"
' End If
'Else
' Wscript.Echo "Success."
'End If
'****************************************
' This will copy the metabase files to the D share.
'****************************************
Dim objFSO
CopyAFile "C:\WINDOWS\system32\inetsrv\MetaBack\portal*.*" , "\\portal\Backups$\MetaBase\"
Sub CopyAFile(vFrom, vTo)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile vFrom, vTo, True
objFSO.CopyFile "C:\WINDOWS\system32\inetsrv\MetaBack\portal*.*" ,"\\portal\Backups$\MetaBase\", True
Set objFSO = Nothing
End Sub