The default VCB scripts do not enable backup of a select disk or disks attached to a VM - vcbMounter.exe will snapshot and backup all disks attached to a VM unless a disk is placed in "Independent" mode meaning it cannot be placed in snapshot mode.
In many situations you may have a VM with a system disk (say 10GB) and an application or data disk (say 50GB) - and you only want to do a full-image backup of the system disk to (and maybe an incremental of the data disk).
This has always frustrated me so I set out to write a script to enable me to export specific VMDKs only.
A description of the process follows.
Attached, you will find a vb script that I have written to perfrom the process from your VCB proxy server. The VBScript takes 2 arguments as shown below:
cscript.exe export_select_disks.vbs <FQDN_OF_VM> <COMMA-SEPARATED_LIST_SCSI_BUS_IDs_OF_DISKS_TO_BACKUP>
e.g.
cscript.exe *export_select_disks.vbs *DEVSQL01.domain.local scsi0.0,scsi0.1
You will need to modify the constants at the top of the script to suit your environment (default mount point, vcb proxy user and password, whether to delete any existing vcb snapshot for the VM etc).
Hope this helps someone!
(if you have trouble reading the below - see attached word doc)
====================================================
FULL IMAGE BACKUP OF INDIVIDUAL DISK USING VCB:
====================================================
NOTE: to create a usable script that implements the following process, will need to be able to feed in relevant command line args to CommVault "Pre-backup" script:
FQDN of VM to backup
COMMA-SEPARATED LIST oF SCSI ID/s oF DISK/s to export (while ignoring other disks)
Process is as follows:
1. GET "VmId" OF VM:
=> vcbVmName -h <vc_server> -u <vc_logon_account> -p <vc_password> -s ipaddr:<FQDN_or_IP_OF_VM>
e.g.
vcbVmName -h myvcserver.domain.local -u vcbproxyuser -p vcbproxypass -s ipaddr:vcbtest2.domain.local
Output (note VM ID in bold😞
Found VM:
moref:vm-14168
name:VCBTEST2
uuid:5026fe86-c802-f99d-b1db-f3d6e9a5e732
ipaddr:10.96.64.136
2. CREATE SNAPSHOT (RETURNS SNAPSHOT ID FOR USE IN SUBSEQUENT COMMANDS):
SYNTAX: vcbSnapshot -h <vc_server> -u <vc_logon_account> -p <vc_password> -c <VmId> <SNAPSHOT_NAME>
=> vcbSnapshot -h myvcserver.domain.local -u vcbproxyuser -p vcbproxypass -c moref:vm-14168 VCB-BACKUP
Output (note snapshot ID in bold😞
2007-10-03 19:06:27.901 'CreateSnapshot' 4316 info Creating snapshot
SsId:snapshot-14259
3. GET LIST OF DISKS IN SNAPSHOT (I.E. ENABLES IDENTIFICATION OF DISK/s TO EXPORT & BACK UP):
=> vcbSnapshot -h myvcserver.domain.local -u vcbproxyuser -p vcbproxypass -l moref:vm-14168 SsId:snapshot-14259
(NOTE: "ssid" and "vmid" values comes from output of previous commands)
Output (note SCSI IDs in bold):
scsi0.0:[DEVSANNET08] VCBTEST2/VCBTEST2_1.vmdk
scsi0.1:[DEVSANNET08] VCBTEST2/VCBTEST2.vmdk
vmx:[DEVSANNET08] VCBTEST2/VCBTEST2.vmx
logdir:[DEVSANNET08] VCBTEST2/
suspenddir:[DEVSANNET08] VCBTEST2/
config0:VCBTEST2.vmsd
config1:VCBTEST2.vmxf
config2:VCBTEST2.nvram
log0:vmware-7.log
log1:vmware-8.log
log2:vmware-9.log
log3:vmware-10.log
log4:vmware-5.log
log5:vmware-6.log
log6:vmware.log
4. EXPORT THE DESIRED VIRTUAL DISK/s (SCRIPT GETS DISK PATH FROM OUTPUT OF PREVIOUS COMMAND):
cd D:\mnt
md VCBTEST2.emapdev.net-CustomDiskBackup
SYNTAX: vcbExport -M 1 -d VCBTEST2_1.vmdk -s "blklst://<snapshot_id><VMDK_PATH>@<vc_servert>?<vc_user>/<vc_pass>"
NOTE: sytax must be precise!
E.G.:
=> vcbExport -M 1 -d D:\mnt\VCBTEST2_1.vmdk -s "blklst://snapshot-14259[DEVSANNET08] VCBTEST2/VCBTEST2_1.vmdk@lonman01.emap.net? vcbproxyuser/vcbproxypass"
Output (over SAN not NIC):
Converting "D:\mnt\VCBTEST2_1.vmdk" (compact file):
0%=====================50%=====================100%
**********************************************************************************
Does block-level export in consolidated format to a single .VMDK file.
Repeat for additional disks
5. POST-DISK-EXPORT COMMAND - COMMIT SNAPSHOT AS PER NORMAL vcbMounter POST-EXPORT PROCESS:
SYNTAX: vcbSnapshot -h <vc_server> -u <vc_logon_account> -p <vc_password> -d <VM_ID> <SNAPSHOT_ID>
E.G.
=> vcbSnapshot -h myvcserver.domain.local -u vcbproxyuser -p vcbproxypass -d moref:*vm-14168 SsId:snapshot-14259*
Then run commands to delete local temp directory holding previously exported vmdk's
6. *SAMPLE COMMAND LINE FOR COMMVAULT PREBACKUP SCRIPT:*_
SYNTAX: cscript.exe export_select_disks.vbs <VM_FQDN> <SCSI_ID1,SCSI_ID2,....>
E.G. (this is what we would specify in "Pre-scan" command line of our backup software (CommVault in our case)):
cscript.exe export_select_disks.vbs DEVSQL01.domain.local scsi0.0,scsi0.1
(this will back up VM disks SCSI(0:0) and SCSI(0:1) on the VM - each to a consolidated .vmdk file)
7. MOUNTING A DISK EXPORTED (BACKED UP) USING vcbExport (LOTS OF OPTIONS - THIS IS ONLY AN EG OF SYNTAX):
(Use for file extraction or as quick test of backup integrity)
SYNTAX: mountvm -cycleId -d <full_path_to_exported_disk_file> <directory_path_for_mount>
E.G.
=> mountvm -cycleId -d D:\mnt\DEVSQL01_DISK_SCSI_0.1.vmdk D:\mnt\temp
Unmount:
SYNTAX: mountvm -u <directory_path_for_mount>
=> mountvm -u D:\mnt\temp
8. HOW TO RESTORE A DISK EXPORTED (BACKED UP) USING vcbExport:
Provided "-M 1" option is used during vcbExport backup, then restore is simple process:
Copy the VMDK to a temp drive on the target ESX server
Import the vmdk file: vmkfstools -i <SOURCE_VMDK_THE_ONE_FROM_vcbExport> <DESTINATION_VMDK>
(NOTE: This will expand the disk to it's original size!)
Now just add the virtual disk to either a new VM, or to original VM (at same SCSI BUS ID as per original disk you are replacing)
See attached files and comments in the VB Script file
This is exactly what I was looking for a long time. Thank you very much for posting this!
This is great. Can't wait to test it out. I'm not so keen on the vb scripting involved...but it doesn't seem to me that the virtual machine config files would get included. Is there any way to add them as well? Thanks!
Great script but found issues with 3.5. As certificates are not set up there is an "error" message in the output of the utilities when run. I disabled error checking in the script and it run but clearly this is not ideal, any chance to amend for 3.5
Hi Dave
Thanks for the feedback
Sorry - have been on extended holiday overseas (nice for some!) and have been moving house.
When I get home ESX platform back up I will ammend (although someone might have already done this!)
Cheers
Justin
Thanks for this script Justin!
I fixed the certificates problem by changing all relevant "error" strings to "error]", imho this should be ok.
Could you give some explanation on what you did to fix the certificate error
Can you oist the revised working script please
Sorry for the delay, I don't watch this post.
I changed lines where the output of command is searched for "error" string to search "error]" because the certificate errors don't contain the bracket (like the rest of error messages).
It was in 5 occurences of InStr command.
Hi,
is it possible to copy some other Files like .vmx etc. LanFree?
Hi I had the same Problems. I Changed a little bit the script added an Host named VMWARE (the same name like in the Certificate)in system32/etc, enabled SSL-Certs with:
"VerifySSLCertificates"=dword:00000001
I switched to use the name of the machines in Virtual Center not the IP/computername
Command like this: cscript /nologo "d:\vcb\generic\BackupDisk.vbs" "EC084479 VC" "scsi0.0,scsi0.1"
The VMDK-Files are compacter then using the pre-Backup Command and only 1 File.
I Tried to backup the VMX-File too(You need it ro revover the machine using "Import Machine") with no success.
If anybody has an Idea to get the VMX File too Please post the solution.
I need an restore tool which is copying the Restored file back to an new Folder on the VMFS too
Thanks all and have fun with the Script
Greetings Dracul/Thomas
the changed Skript starts here:
'// ===========================================================================================
'// BackupDisk.vbs
'// -
'// Uses VCB command line utils, primarily "vcbExport", to do snapshot and perform a full-image
'// backup of an *** individual *** VM disk file.
'//
'// Script is designed to be called as "Pre-scan" or "Pre-backup" script by a CommVault sub-client backup job for the VM that is to be backed up
'//
'// This differs from the default vcbMounter.exe utility which enuerates ALL disks in a VM and does
'// not enable granular full-image backup of single disk - although it will skip "independent" disks
'//
'// The problem is that if disks are put into independent mode, vcbMounter will also skip them for
'// *** File-level *** backups.
'//
'// The "BackupDisk.vbs" script enables selective full-image backup of a specified disk or disks while maintaining
'// the ability to perfrom VCB file-level backups of any/all disks within the VM using default VCB scripts
'//
'// It also provides a workaround for the VCB 1.0.2 / ESX 3.0.1 bug that prevents backups of disks on a given VM succedding where that VM
'// has multiple disks attached on different LUNs.
'//
'// The script performs the following steps:
'// -
'// =>. Reads the values for the following required command-line parameters:
'// * FQDN of target VM where disk to be backed up resides
'// * Comma-separated list of the SCSI ID/s of the disk or disks within that VM that should be backed up e.g. "scsi0.0" or "scsi0.0,scsi0.1"
'//
'// IMPORTANT NOTE ON FORMAT OF SCSI ID/s PROVIDED TO COMMAND LINE:
'// SCSI IDs should always be provided to the command line in the format "scsi[x].[x]" e.g. "scsi0.0"
'// In this instance "scsi0.0" will always be the first disk (System drive for Windows servers), "scsi0.1" will be the second disk etc ...
'// The SCSI ID for a disk can be obtained by viewing the properties of the VM in Virtual Center
'// However, the display format in Virtual Centre will be as "SCSI (.[x])" e.g. "SCSI (0.0)"
'// !!!! This format should be changed: remove all spaces and "(" ")" brackets from the way it is displayed.
'// For example, "SCSI (0:0)" should be modified to "scsi0.0"
'//
'// =>. Gets ID of VM using vcbVmName
'// =>. Snapshots the VM using vcbSnapshot
'// =>. Runs vcbSnapshot with the "-l" parameter to enumerate the disks within the snapshot
'// =>. Checks SCSI ID/s of disk/s passed on command line againsts list of disks within snapshot, and returns path of associated VMDK/s on SAN
'// =>. For each disk specified on command line, runs vcbExport to export disk in "compact" and "monolithic" format.
'// The export path will be \[FQDN_OF_VM]\[ORIGINAL_VMDK_FILE_NAME]
'// e.g. D:\MNT\vmtest1.emapdev.net\VMTEST1_1.vmdk
'// =>. Runs vcbSnapshot a 3rd time to commit the snapshot (i.e. once vcbExport of all specified disks is complete)
'//
'// POST_EXECUTION ASSUMPTIONS FOR COMMVAULT:
'// * It will then be assumed that CommVault will back up the exported disk image from the path specified in step 5 above -
'//
'// * It will also be assumed that CommVault will run a "post-backup" script to DELETE the D:\MNT\[VM Name] directory on the VCB server
'// after backup completes
'//
'// Prerequisites:
'// -
'// * VMWare Consolidated Backup Framework 1.0.x must be installed on system where script is executed
'// * The script MUST be located in the VCB_PROXY_FRAMEWORK_INSTALL_DIR\generic folder - along with the other .wsf, .js and .bat files
'// By default this is "C:\Program Files\VMware\VMware Consolidated Backup Framework\generic"
'// * The config.js file must be correctly configured as per VMWare / CommVault / Emap requirements
'// * The constant "VCB_INSTALL_PATH" within the script below must be modified to reflect the location of the VCB executables (vcbExport, vcbSnapshot, vcbVmName etc)
'//
'// Other notes:
'// -
'// As per any VCB-based backup, only one backup of the VM specified should be run at any one time (stands to reason)
'//
'// Usage / Syntax:
'// -
'//
'// Examples:
'// -
'// To backup disk 0 on VM "vcbtest1.emapdev.net":
'// BackupDisk.vbs vcbtest1.emapdev.net scsi0.0
'//
'// To backup disks 0 and 1 on VM "server1.emap.net":
'// BackupDisk.vbs server1.emap.net scsi0.0,scsi0.1
'//
'// Restoring vcbExport backups made with this script:
'// -
'// The compact, monolithic .VMDK files created by this script as individual disk backups can be restored by using "vmkfstools -i" on any ESX service console
'// The VMDK backup file should be:
'// 1. Restored to the VCB server local disk using CommVault
'// 2. Copied to a temp location on one of the ESX servers in the correct VI cluster
'// 3. Then imported to the correct folder for the target VM (existing or new) using "vmkfstools -i
'// 4. Finally, the imported vmdk file should be re-added to the correct VM using ESX command line or Virtual Infrastructure client
'//
'// AUTHOR: Justin Turver, 09/2007
'// Changes: Thomas Hierl 02/2009
'// ===========================================================================================
Option Explicit
'// -
'// Constants - change to reflect running environment:
'// -
Const VCB_INSTALL_PATH = "D:\VCB"
Const HOST = "VMware" '// "EC084479.ecdomain.net"
Const USERNAME = "Administrator"
Const PASSWORD = "*************"
Const BACKUPROOT = "K:
mnt"
Const SNAPSHOTNAME = "_VCB-BACKUP_"
Const CONTINUE_IF_VCB_SNAP_FOUND = True '// Set to true to proceed with backup/export even if there's an existing snapshot of the VM
Const CONTINUE_IF_BACKUP_DIR_FOUND = True '// Set to true to proceed with backup/export even if the local backup target directory already exists
'// -
Const EVT_SUCCESS = 0
Const EVT_ERROR = 1
Const EVT_WARN = 2
Const EVT_INFO = 4
'// Global Variables
'// -
Dim oArgs, oWshShell, oExec, oDict, oDictItem, colKeys, oFSO, oBackupFolder
Dim aDisksToBackUp, aSSIDs
Dim iRetVal, i
Dim sVMFQDN, sOutput, sCommandPath, sVmID, sSSID, sSnapNumber, sSnapDelete, sSnapCreate, sDisk, sDisks, sDiskPath, sDiskFile, sKey, sPercentExportComplete
Dim bDiskCheck
Dim start
'// Create global objects
'// -
Set oWshShell = CreateObject("WScript.Shell")
Set oDict = CreateObject("Scripting.Dictionary")
Set oFSO = CreateObject("Scripting.FileSystemObject")
'// ==============================================
'// START MAIN:
'// ==============================================
start = Now()
LogInfo( "EMAP vcbEXPORT: Starting backup using " & WScript.ScriptFullName )
'// ==============================================
'// 1. Get / check command line params:
'// ==============================================
LogInfo( "EMAP vcbEXPORT task 1: Checking command-line params for Emap custom VCB Backup script " & WScript.ScriptFullName )
Set oArgs = WScript.Arguments
If oArgs.Count = 2 Then
sVMFQDN = Trim((WScript.Arguments(0)))
' // sVMFQDN = chr(34) & sVMFQDN & chr(34)
On Error Resume Next
'// aDisksToBackup enthält alle einträge der zu sichernden Daten
aDisksToBackUp = Split(LCase(WScript.Arguments(1)),",")
If Err Then
LogError("EMAP vcbEXPORT task 1: ERROR: Invalid command-line argument specified for 'disk/s' paramter. ERROR: " & Err.Number & "-" & Err.Description & ". VM: " & sVMFQDN)
LogError("Expected Syntax = e.g. '" & WScript.ScriptName & " mytestvm.emapdev.net scsi0.0,scsi0.1'. VCB BACKUP FAILED!")
WScript.Quit(1)
End If
On Error Goto 0
Else
LogError("EMAP vcbEXPORT task 1: ERROR: Invalid command line arguments specified. Syntax = . VM: " & sVMFQDN & ". VCB BACKUP FAILED!")
WScript.Quit(1)
End If
Set oArgs = Nothing
LogInfo( "EMAP vcbEXPORT task 1: Command line successfully parsed. Will attempt to backup server '" & sVMFQDN & "'. The following disks on this server will be backed up: " & WScript.Arguments(1))
'// ==============================================
'// 2. Get ID of VM for use when creating snapshot
'// ==============================================
oWshShell.LogEvent EVT_INFO, "EMAP vcbEXPORT task 2: Retrieving VM ID of server '" & sVMFQDN & "' for vcbBackup."
'// HIE Org mit IPAdresse
'// sVmID = RunCommand(VCB_INSTALL_PATH & "\vcbVmName.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -s ipaddr:" & sVMFQDN,"moref:",False)
'//
sVmID = RunCommand(VCB_INSTALL_PATH & "\vcbVmName.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -s Name:" & chr(34) & sVMFQDN & chr(34) ,"moref:" ,False)
If Len(Trim(sVmID)) < 10 Then
LogError("EMAP vcbEXPORT task 2: UNKNOWN ERROR: vcbVmName could did not return the vm-ID for VM: " & sVMFQDN & ":" & sVmID & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
WScript.Quit(1)
End If
LogInfo( "EMAP vcbEXPORT task 2: ID of VM '" & sVMFQDN & "' returned successfully: " & sVmID & vbCrLf & vbCrLf & sOutput)
sOutput = ""
'// ==========================================================================
'// 3.Create backup folder for VM at designated local mount point (BACKUPROOT)
'// ==========================================================================
'// Check if backup folder on vcb proxy server (subfolder to default mount point) exists:
LogInfo( "EMAP vcbEXPORT task 3: Creating backup folder for '" & sVMFQDN & "' at root path '" & BACKUPROOT & "'.")
If oFSO.FolderExists(BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup") Then
If CONTINUE_IF_BACKUP_DIR_FOUND = True Then '// Proceed with backup anyway - remove existing folder and continue
'// Log warning as old backup may not have run post-backup cleaup script (post-backup)
LogInfo( "EMAP vcbEXPORT task 3: WARNING: vcb export backup folder already exists for VM '" & sVMFQDN & "' at path: '" & BACKUPROOT & "\" & sVMFQDN & "' and 'CONTINUE_IF_BACKUP_DIR_FOUND = True' - will proceed and remove existing backup directory and current backup will continue. NOTE: This folder should have been removed by post-backup script. Check that the correct post-backup script exists for CommVault backup of this server. The fact that it's still there may also mean that the previous backup of this VM failed, or the post-backup script failed. Please check this out. Script " & WScript.ScriptFullName & " will continue to delete the existing directory and all files within. VCB BACKUP WARNING!")
'// Try and remove the existing folder and contents
On Error Resume Next
Set oBackupFolder = oFSO.GetFolder(BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup")
oBackupFolder.Delete ', True
If Err Then
LogError("EMAP vcbEXPORT task 3: ERROR: Unable to delete an existing vcb export folder '" & BACKUPROOT & "\" & sVMFQDN & "'.for VM '" & sVMFQDN & "'. Check that another backup is not running, or that the folder or files within are not otherwise locked!!!. Error: " & Err.Number & "--" & Err.Description & ". VCB BACKUP FAILED!")
WScript.Quit(1)
End If
On Error Goto 0
Set oBackupFolder = Nothing
WScript.Sleep 2000
Else
'// Cancel backup ...
LogError("EMAP vcbEXPORT task 3: ERROR: backup target folder for VM '" & BACKUPROOT & "\" & sVMFQDN & "'already exists, and 'CONTINUE_IF_BACKUP_DIR_FOUND' is set to 'FALSE'. Check that another backup is not running, and that any CommVault backup jobs for this VM have the correct post-backup script assigned so that backup directories or mount points for this VM are removed properly once backup is complete. Backup cannot continue for this VM. VCB BACKUP FAILED!")
WScript.Quit(1)
End If
End If
'// Create backup folder for the VM at the specified mount point root 'BACKUPROOT'
On Error Resume Next
Set oBackupFolder = oFSO.CreateFolder(BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup")
If Err Then
LogError("EMAP vcbEXPORT task 3: ERROR: Unable to create local vcb export folder '" & BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup" & "'.for VM '" & sVMFQDN & "'. Check that another backup is not running, and that the folder does not already exist in a locked state!!!. Error: " & Err.Number & "--" & Err.Description & ". Backup cannot continue for this disk. VCB BACKUP FAILED!")
WScript.Quit(1)
Else
LogInfo( "EMAP vcbEXPORT task 3: Backup folder for VM '" & sVMFQDN & "' created successfully at '" & BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup" & "'.")
End If
On Error Goto 0
Set oBackupFolder = Nothing
'// ==============================================
'// 4. Check for existing vcbSnapshots
'// ==============================================
LogInfo("EMAP vcbEXPORT task 4: Checking for existing VCB snapshots ('_VCB-BACKUP_') for VM: " & sVMFQDN)
sSSID = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & "*******" & " -f " & sVmID & " " & SNAPSHOTNAME, "ssid:",False)
If (InStr(LCase(sOutput),"no backup snapshots found") > 0) Or (InStr(LCase(sSSID),"ssid:snapshot") = 0) Then
'// No VCB snapshots found
LogInfo( "EMAP vcbEXPORT task 4: No existing VCB Snapshots found for VM: " & sVMFQDN & ". Backup will proceed.")
Else
'// Existing VCB snapshots found
If CONTINUE_IF_VCB_SNAP_FOUND = True Then
LogInfo( "EMAP vcbEXPORT task 4: Existing VCB Snapshots found for VM: " & sVMFQDN & ", and 'CONTINUE_IF_VCB_SNAP_FOUND = True' - proceeding to delete existing VCB snapshot ...")
'// Delete existing VCB snap/s, and continue backup
sSnapDelete = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -d " & sVmID & " " & sSSID, "error",False)
'// Scheiß Error wegen Certifikat HIE
If InStr(LCase(sSnapDelete), "error") Then
LogError("EMAP vcbEXPORT task 4: ERROR: Cannot delete existing snapshot: " & sVMFQDN & ": " & sSSID & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
WScript.Quit(1)
Else
LogInfo( "EMAP vcbEXPORT task 4: Existing snapshot of VM '" & sVMFQDN & "', VMID=" & sVmID & ", SSID=" & sSSID & " - deleted successfully." & vbCrLf & vbCrLf & sOutput)
End If
WScript.Sleep 5000
Else
'// Log error and fail backup ..
LogError("EMAP vcbEXPORT task 4: ERROR: Existing VCB Snapshots found for VM: " & sVMFQDN & ", and 'CONTINUE_IF_VCB_SNAP_FOUND = False', so backup will not proceed. VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
Err.Clear
WScript.Quit(1)
End If
End If
sOutput = ""
sSSID = ""
'// ===============================================
'// 5. Create snapshot of the vm specified by VmID
'// ===============================================
LogInfo( "EMAP vcbEXPORT task 5: Creating snapshot of VM '" & sVMFQDN & "' for vcbBackup.")
sSSID = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -c " & sVmID & " " & SNAPSHOTNAME, "ssid",False)
'//If (Len(Trim(sSSID)) < 10) Or (InStr(LCase(sOutput), "error") > 1 ) Then
If Len(Trim(sSSID)) < 10 Then
LogError("EMAP vcbEXPORT task 5: UNKNOWN ERROR: vcbSnapshot did not successfully snapshot the VM: " & sVMFQDN & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
WScript.Quit(1)
Else
LogInfo( "EMAP vcbEXPORT task 5: Snapshot of VM '" & sVMFQDN & "' created successfully. Snapshot ID: " & sSSID & vbCrLf & vbCrLf & sOutput )
End If
sOutput = ""
'// ==================================================================
'// 6. Get paths for source disks on SAN ready for vcbExport backup
'// ==================================================================
LogInfo( "EMAP vcbEXPORT task 6: Retreiving SAN paths for VM disk/s to be backed up for VM '" & sVMFQDN & "'")
'// Get dictionary object holding paths of all disks in the snapshot ...
'// NOTE that the "True" parameter at the end fo the following command instructs the "RunCommand" function
'// to add all matches to a dictionary object/array (global variable "oDict"), rather than just returning a single string match
sDisks = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -l " & sVmID & " " & sSSID, "scsi", True)
'// Scheiß Error wegen Certifikat HIE
' HIE Prüfung auf SSL-Zertifikat einschalten
oWshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Consolidated Backup\VerifySSLCertificates",1,"REG_DWORD"
If Err.Number <> 0 then
LogError(" Fehler beim Ändern der Registry (VerifySSLCertificates) auf 1 " + VbCrLf + "oWshShell.RegWrite HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Consolidated Backup\VerifySSLCertificates,1,REG_DWORD")
end if
If (InStr(LCase(sOutput), "error") > 0) Then
LogError("EMAP vcbEXPORT task 6: UNKNOWN ERROR: vcbSnapshot did not successfully list disks in : " & sSSID & " for VM: " & sVMFQDN & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
WScript.Quit(1)
Else
LogInfo( "EMAP vcbEXPORT task 6: Successfully listed disks in snapshot for VM '" & sVMFQDN & "' for snapshot " & sSSID & vbCrLf & vbCrLf & sOutput )
End If
sOutput = ""
colKeys = oDict.Keys
'// ==================================================================
'// 7. Then run vcbExport to export the disk file to the specified
'// mount point
'// ==================================================================
'// For each disk specified for backup on the commane line:
For i = 0 To UBound(aDisksToBackUp)
'// Check to see if the disk exists in the snapshot using "vcbSnapshot -l"
'// If it does, obtain the corresponding SAN path from the output of "vcbSnapShot -l"
'// by removing the "scsiX.X:" part of the string
'// The remaining portion of the string which is obtained is the correct
'// source-path path for the disk as it should be passed to the vcbExport command
bDiskCheck = False
sDiskPath = ""
sDiskFile = ""
'// Get full path of disk in correct case ...
For Each sKey in oDict.Items
sDisk = Trim(oDict.Item(sKey))
If InStr(sDisk, aDisksToBackUp(i)) Then
sDiskPath = Mid(sDisk,InStr(sDisk,":")+1, Len(sDisk)-InStr(sDisk,":"))
bDiskCheck = True
End If
Next
'// If SAN path for disk is returned successfully, run vcbExport for the disk:
If (bDiskCheck = True) And InStr(LCase(sDiskPath),(".vmdk")) Then
'// Try export ###################################################################################
sDiskFile = Trim(Mid(sDiskPath,InStrRev(sDiskPath, "/")+1,Len(sDiskPath)-InStrRev(sDiskPath, "/")))
LogInfo( "EMAP vcbEXPORT task 7: Running vcbExport to backup disk '" & sDiskPath & "' for VM '" & sVMFQDN & "'")
sSnapNumber = Mid(sSSID,InStr(sSSID,":")+1, Len(sSSID)-InStr(sSSID,":"))
sPercentExportComplete = RunCommand(VCB_INSTALL_PATH & "\vcbExport.exe -M 1 -d " & chr(34) &BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup\" & sDiskFile & CHR(34) & " -s " & Chr(34) & "blklst://" & sSnapNumber & sDiskPath & "@" & HOST & "?" & USERNAME & "/" & PASSWORD & Chr(34),"100%",False)
If (InStr(sPercentExportComplete, "100%") > 0) And (InStr(LCase(sOutput),"error") < 1) Then
'// Export ** should ** have worked ...
'// Check file size on disk to make sure ...
LogSuccess( "EMAP vcbEXPORT task 7: vcbExport of disk '" & sDiskPath & "' to path '" & BACKUPROOT & "\" & sVMFQDN & "\" & sDiskFile & "', for VM '" & sVMFQDN & "' completed successfully!" & vbCrLf & vbCrLf & sOutput)
Else
'// Export failed ....
LogError("EMAP vcbEXPORT task 7: ERROR: vcbExport of disk '" & sDiskPath & "' to path '" & BACKUPROOT & "\" & sVMFQDN & "\" & sDiskFile & "', For VM '" & sVMFQDN & "' failed! VCB BACKUP FAILED for this disk!" & vbCrLf & vbCrLf & sOutput)
End If
Else
'// Fail backup for this disk - cannot proceed without correct source path of disk to backup
LogError("ERROR: " & sVMFQDN & "EMAP vcbEXPORT task 7: Unable to obtain source path on SAN for disk " & sDisk & ". This disk will NOT be backed up! VCB BACKUP FAILED for this disk!" & vbCrLf & vbCrLf & sOutput)
End If
sOutput = ""
Next
' HIE Prüfung auf SSL-Zertifikat wieder ausschalten
oWshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Consolidated Backup\VerifySSLCertificates",0,"REG_DWORD"
If Err.Number <> 0 then
LogError(" Fehler beim Ändern der Registry (VerifySSLCertificates) auf 0 " + VbCrLf + "oWshShell.RegWrite HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Consolidated Backup\VerifySSLCertificates,0,REG_DWORD")
end if
'// For debug
sOutput = ""
' '// ####### Backup VMX-Datei ####################################################################################
' '// ==================================================================
' '// 6a. Get paths for source disks on SAN ready for vcbExport backup
' '// ==================================================================
'
' oWshShell.LogEvent EVT_INFO, "EMAP vcbEXPORT task 6a: Retreiving SAN paths for VMX to be backed up for VM '" & sVMFQDN & "'"
'
' '// Get dictionary object holding paths of all disks in the snapshot ...
' '// NOTE that the "True" parameter at the end fo the following command instructs the "RunCommand" function
' '// to add all matches to a dictionary object/array (global variable "oDict"), rather than just returning a single string match
' sDisks = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -l " & sVmID & " " & sSSID, "vmx", True)
'
' '// Scheiß Error wegen Certifikat HIE
' If (InStr(LCase(sOutput), "error") > 0) Then
' LogError("EMAP vcbEXPORT task 6a: UNKNOWN ERROR: vcbSnapshot did not successfully list disks in : " & sSSID & " for VM: " & sVMFQDN & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
' WScript.Quit(1)
' Else
' oWshShell.LogEvent EVT_INFO, "EMAP vcbEXPORT task 6a: Successfully listed disks in snapshot for VM '" & sVMFQDN & "' for snapshot " & sSSID & vbCrLf & vbCrLf & sOutput
' End If
'
' sOutput = ""
' colKeys = oDict.Keys
' '// ==================================================================
' '// 7a. Then run vcbExport to export the disk file to the specified
' '// mount point
' '// ==================================================================
' bDiskCheck = False
' sDiskPath = ""
' sDiskFile = ""
' '// Get full path of disk in correct case ...
' For Each sKey in oDict.Items
' sDisk = Trim(oDict.Item(sKey))
' If InStr(sDisk, "vmx") Then
' sDiskPath = Mid(sDisk,InStr(sDisk,":")+1, Len(sDisk)-InStr(sDisk,":"))
' bDiskCheck = True
' End If
' Next
' '// If SAN path for disk is returned successfully, run vcbExport for the disk:
' If (bDiskCheck = True) And InStr(LCase(sDiskPath),(".vmx")) Then
' '// Try export ###################################################################################
' sDiskFile = Trim(Mid(sDiskPath,InStrRev(sDiskPath, "/")+1,Len(sDiskPath)-InStrRev(sDiskPath, "/")))
' oWshShell.LogEvent EVT_INFO, "EMAP vcbEXPORT task 7: Running vcbExport to backup disk '" & sDiskPath & "' for VM '" & sVMFQDN & "'"
' sSnapNumber = Mid(sSSID,InStr(sSSID,":")+1, Len(sSSID)-InStr(sSSID,":"))
' sPercentExportComplete = RunCommand(VCB_INSTALL_PATH & "\vcbExport.exe -M 1 -d " & chr(34) &BACKUPROOT & "\" & sVMFQDN & "-CustomDiskBackup\" & sDiskFile & CHR(34) & " -s " & Chr(34) & "blklst://" & sSnapNumber & sDiskPath & "@" & HOST & "?" & USERNAME & "/" & PASSWORD & Chr(34),"100%",False)
' If (InStr(sPercentExportComplete, "100%") > 0) And (InStr(LCase(sOutput),"error") < 1) Then
' '// Export ** should ** have worked ...
' '// Check file size on disk to make sure ...
' oWshShell.LogEvent EVT_SUCCESS, "EMAP vcbEXPORT task 7a: vcbExport of disk '" & sDiskPath & "' to path '" & BACKUPROOT & "\" & sVMFQDN & "\" & sDiskFile & "', for VM '" & sVMFQDN & "' completed successfully!" & vbCrLf & vbCrLf & sOutput
' Else
' '// Export failed ....
' LogError("EMAP vcbEXPORT task 7a: ERROR: vcbExport of disk '" & sDiskPath & "' to path '" & BACKUPROOT & "\" & sVMFQDN & "\" & sDiskFile & "', For VM '" & sVMFQDN & "' failed! VCB BACKUP FAILED for this disk!" & vbCrLf & vbCrLf & sOutput)
' End If
' Else
' '// Fail backup for this disk - cannot proceed without correct source path of disk to backup
' LogError("ERROR: " & sVMFQDN & "EMAP vcbEXPORT task 7a: Unable to obtain source path on SAN for disk " & sDisk & ". This disk will NOT be backed up! VCB BACKUP FAILED for this disk!" & vbCrLf & vbCrLf & sOutput)
' End If
' sOutput = ""
'
'//############################################################################################
'// ==================================================================
'// 8. Remove snapshot once disk export is complete
'// ==================================================================
WScript.Sleep 5000
LogInfo( "EMAP vcbEXPORT task 8: POST DISK EXPORT (vcbExport) CLEANUP: Removing snapshot of VM '" & sVMFQDN & "' for vcbBackup.")
sSSID = RunCommand(VCB_INSTALL_PATH & "\vcbSnapshot.exe -h " & HOST & " -u " & USERNAME & " -p " & PASSWORD & " -d " & sVmID & " " & sSSID, "error",False)
If InStr(LCase(sSnapDelete), "error") Then
LogError("EMAP vcbEXPORT task 8: ERROR: Cannot delete existing snapshot: " & sVMFQDN & ": " & sSSID & ". VCB BACKUP FAILED!" & vbCrLf & vbCrLf & sOutput)
Else
LogInfo( "EMAP vcbEXPORT task 8: POST DISK EXPORT (vcbExport) CLEANUP: Existing snapshot of VM '" & sVMFQDN & "', VMID=" & sVmID & ", SSID=" & sSSID & " - deleted successfully." & vbCrLf & vbCrLf & sOutput)
End If
'// ======================
'// BACKUP COMPLETE
'// ======================
LogInfo( "EMAP vcbEXPORT: backup of VM '" & sVMFQDN & "' COMPLETE!")
'// =====================
'// Clean up
'// =====================
Set oFSO = Nothing
Set oDict = Nothing
Set oWshShell = Nothing
'// ===========================
'// FUNCTIONS
'// ===========================
Function RunCommand(sPath, sSearchVal, bAddToDict)
Dim sRetVal, oExecRun, sLineText, sStdErr
LogCommand("*****RunCommand:" & sPath)
oWshShell.LogEvent EVT_INFO, sVMFQDN & ": Running command '" & sPath & "'"
Set oExecRun = oWshShell.Exec(sPath)
If Err Then
LogError("ERROR: Error executing command: '" & sPath & "'. " & Err.Number & "-" & Err.Description & ". VM: " & sVMFQDN & ". VCB BACKUP FAILED!")
WScript.Quit(1)
End If
On Error Goto 0
Do While oExecRun.Status = 0
WScript.Sleep 100
Loop
Do Until oExecRun.StdOut.AtEndOfStream
sLineText = oExecRun.StdOut.ReadLine
If InStr(LCase(sLineText), LCase(sSearchVal)) Then
sRetVal = Trim(sLineText)
If bAddToDict = True Then
'// Add all matches to array (global dictionary object 'oDict')
oDict.Add sRetVal,sRetVal
End If
End If
sOutput = sOutput & vbCrLf & sLineText
sLineText = ""
Loop
sStdErr = Trim(oExecRun.StdErr.ReadAll)
If Len(Trim(sStdErr)) > 0 Then
LogError("ERROR: Error returned running command '" & sPath & "' for VM: "& sVMFQDN & ". Error: " & sStdErr & ". Backup ** may ** have failed for this VM!")
End If
LogInfo("******* Antwort:" & sRetVal)
Set oExecRun = Nothing
RunCommand = sRetVal
End Function
Function LogCommand(sMsg)
' kein Eintrag in Evt-log wegen Passwort
Dim oShell
sMsg = "INFO (+" & Dauer & " s):" & sMsg
Set oShell = CreateObject("WScript.Shell")
WScript.StdOut.WriteLine sMsg
Set oShell = Nothing
End Function
Function LogError(sMsg)
Dim oShell
sMsg = "Error (+" & Dauer & " s):" & sMsg
Set oShell = CreateObject("WScript.Shell")
WScript.StdOut.WriteLine sMsg
oWshShell.LogEvent EVT_ERROR, sMsg
Set oShell = Nothing
End Function
Function LogInfo(sMsg)
Dim oShell
sMsg = "INFO (+" & Dauer & " s):" & sMsg
Set oShell = CreateObject("WScript.Shell")
WScript.StdOut.WriteLine sMsg
oWshShell.LogEvent EVT_INFO, sMsg
Set oShell = Nothing
End Function
Function LogSuccess(sMsg)
Dim oShell
sMsg = "ERFOLG (+" & Dauer & " s):" & sMsg
Set oShell = CreateObject("WScript.Shell")
WScript.StdOut.WriteLine sMsg
oWshShell.LogEvent EVT_SUCCESS,sMsg
Set oShell = Nothing
End Function
Function Dauer
Dauer = DateDiff("s",start,Now())
End Function
Awesome!!!!
You've no idea how much grief this has saved us!
Oh yeah one other thing apart from the Awesome...and it was Awesome!
Setup an NFS data store and save your self hours waiting for the vmdk file to copy to a temp folder in the ESX server.
(I found it took three hours to copy a 6GB .vmdk file to the ESX server using WINSCP. WINSCP always takes hours...another story).
You'll need to install Microsoft Windows Services for UNIX on the vcb proxy server.
I found the vmkfstools -i was as fast when using the NFS datastore as when using the FC Datastore. A 6GB VMDK took 30 minutes to import.
Hi LondonIT
We are using FC-San there ist the Backup using in my script much faster.
550GB vmdk files in 2,5 hours (scriptet all VM´s)
The best thing is I copy only used data and not like the VCB-Backup Software all space including empty space.
The next Point is I copy the Data directly via FC-HBA out of the SAN
Greeting Dracul
Thomas -
You could possibly use putty's "psftp" utility in a script to copy the vmx and vmxf files.
Dave Convery
VMware vExpert 2009
http://www.dailyhypervisor.com
!http://communities.vmware.com/servlet/JiveServlet/downloadImage/5441/VMW_vExpert_Q109_200px.jpg|height=50|width=100|src=http://communities.vmware.com/servlet/JiveServlet/downloadImage/5441/VMW_vExpert_Q109_200px.jpg!
Careful. We don't want to learn from this.
Bill Watterson, "Calvin and Hobbes"
Thomas, I am also revising a doc I published on VI:OPS. If you would like, you could attach this script to the doc posting:
http://viops.vmware.com/home/docs/DOC-1392
Dave Convery
VMware vExpert 2009
http://www.dailyhypervisor.com
Careful. We don't want to learn from this.
Bill Watterson, "Calvin and Hobbes"
has anyone got selective backups to work with hot add mode
i have create a script with winscp and exclude .vmdk files.
any chance you can post the script here
I don´t know how to post files here, but I´m ready with the full backup solution.
interested people can write to me I´ll mail the scripts
Thomas.Hierl"add"sca.com
please set the subject to:VCB-Backup I´ll send it Home because I´m in Holyday tomorrow
here the readme-File:
Author Thomas Hierl SCA Packaging Containerboard Deutschland GmbH
Szenario:
3 ESX-Server 3.5 connected to SAN with 3 VMFS-Volumes (Data1, Data2, Data3) and 2 RDM´s (DB-Server and Fileserver)
VCB Backup Proxy with c: d: e: k: (drive K is San 3,6TByte)
d:\VCB
k:\Backup -> Target for other Backups
k:\mnt -> Where VCB creates the Backups
k:\Save_NT01 -> Target of File Backup if the Fileserver
k:\Save_VM -> Target of the vmdk, vmx and vmfx Files Image Backup of VM-Ware Boxes
What does it
these Scrips are backing up all nessesary Data using vcbExport and browse-start over the SAN (not Network)
it needs for 620GB round about 3,5 hours for all the vmdk´s and about 1hour for the Changes on our Fileserver
Start Points over scheduled Tasks
K:\Backup\backup_vmdk.bat -> Backing up all nessesary images to k:\Save_VM
K:\Backup\Start_BKUP.bat -> Backing up the Fileserver Data to k:\Save_NT01 and all other Backups to k:\Backup
K:\Backup\Clean_Log.bat -> Moving and cleaning the logfiles
Veritas Backup exec is saving every day the Target Directory to Tape
k:\Backup
k:\Save_NT01
k:\Save_VM (only Weekly)
Needet software
Robocopy
WinSCP
Putty
Usefull software
Eraser (cleans the unused space with '0000' perfect to compress the vmdk-files (180GB -> 62GB)
Please install on all Servers witch Drives contain much deleted Files
This current version of Eraser is maintained by Garrett Trant. (http://www.heidi.ie)
Sami Tolvanen, the original author of Eraser was a student in the university of technology in Finland.
You can learn more by visiting his home page at http://www.tolvanen.com/sami/
Installation and Operation
S0000625 = vcb Proxy and Backup Server (real HW with connection to SAN See VCB-Installation)
S0001176 = Fileserver (c: d: = vmdk, e: = RAW (Virtual used for the Backup Files script))
EC084479 = Virtual Center (c: d: = vmdk)
C:\WINDOWS\system32\drivers\etc\hosts add:
10.112.83.190 VMware ec084479.ecdomain.net #VMware VirtualCenter
this is needet for the SSL because the certificat name is VMWARE and not the real name of the Virtual Venter. Shit bug.
BackupDisk.vbs (thi is the script which is backing up the VMDK´s and starting the get_vmx.bat)
fill these Constants
Const VCB_INSTALL_PATH = "D:\VCB"
Const HOST = "VMware" '// Name of the Virtual Center (see Host-File)
Const USERNAME = "*********" '// Username of the Virtual Venter
Const PASSWORD = "*******" '// Password of the VC-User
Const ESX_PASSWORD = "*******" '// Password for the Rootaccount for the ESX-Server
Const BACKUPROOT = "K:
mnt"
get_VMX.bat (is creating the script and starting the script to copy the .VMX files to the Backup destination)
this line:
echo open root:%3@esx1.aschaffenburg.packaging.sca.se >> d:\vcb\PuTTY\script.tmp
You have to type in the DNS-Name of the ESX-Server which has a connection to all VMFD-Volumes (Data1-3 etc...)
User for the Copy is root and the Password is defined in BackupDisk.vbs
Have fun with it
Dracul
This is gret stuff! Would you mind posting it on VI:OPS - http://viops.vmware.com ?
This will allow you to post the comments above along with the actual scripts.
Dave Convery
VMware vExpert 2009
http://www.dailyhypervisor.com
Careful. We don't want to learn from this.
Bill Watterson, "Calvin and Hobbes"
fyi "sdelete" from Sysinternals (aka Microsoft) will zero-out deleted data too if anyone needs another option:
http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
Zipfile is posted in http://viops.vmware.com/home/thread/1421
Comments and Questions I will try to answer
Dracul
Hi,
I was inspired by you script to create a script that would mount a virtual machines vmdk's in either fullVM or file based VCB backup, on a disk by disk basis, in a single command e.g. for a file server where the system disk is a fullvm backup, and the data disks are file based backups.
Creating a file or fullVM VCB backup on a disk by disk basis
Jamie.
@Jamie Morrison:
Your vbs script works great for me.
Can someone please add a option to whitch creates a temporlay mountpoint folder and after backup delete it.
come to visit the interesting wonderful article,you will find someing useful.Spring is coming, we provide Vibram fivefingersfor you. so many style you can choose vibram five fingers ksovibram five fingers bikilavibram five fingers classicand we also supply
Is it possible to use this method to backup individual disks of VMs running on single ESXi and placed on this ESXi local datastore?