vmbk.pl Version 2.22.2 Rev.6
by Massimiliano Daneri
email: m.daneri@vmts.net


NAME
vmbk.pl - VMware ESX Server copy disk utility

USAGE
usage: vmbk.pl -h | -d directory  |-f <params> |-B <params> |-G <params> <option>

-h print this help message

-d backup destination directory
-f ftp server syntax: ftp='host',dir='remote directory',user='user name',
password='password',passive='true|false',timeout=<number>
-B use Veritas Netbackup syntax:
policy
='policyname'[,master='masterserver'][,clientname='clientname'][,logfile='logfile][,prepost=true|false]
-G use Legato Networker syntax:
server='servername',group='groupname',[,pool='poolname'][,clientname='clientname']
-M use Tivoli Storage Manager

OPTIONS

-n nfs mount syntax:
    nfs
='host:/share',mountpoint='/dir',options='options'
-s smb mount syntax:
    smb
='//host/share'[,mountpoint='/dir'][,user='domain\\user name'][,password='password'][,options='options']
-e send a report by email syntax :
    smtp
='host',to='email address'[,from='email address'][,encode='encode type'][,html=true|false]
-y
[facility=<facility>],{level=<level>] use syslog to trace events default 'local6' and 'info'

-l TEXT logfile
-L HTML logfile
-t test mode
-i interactive mode
-H don't display header
-a backup all VM also guest with backup="manual"
-1 use always vmdk extension (for export)
-0 use always dsk extension (for export)
-3 the exported virtual disk contains the redo log if exist
-4 backup configuration file and CMOS
-c create restore command on export directory
-m export disk to unique directory
-j set minimum space permitted on destination directory DEFAULT = 1024 (value in MB)
-J set min space permitted on VMFS partition to permit REDO disk DEFAULT = 512 (value in MB)
-z use command cp instead of vmkfstools
-R use vmkfstool(raw mode more faster than cp. !!caution with smb share!!)command to disk instead of cp
-5 set pre directory name (default 'vm-')
-b Backup session DEFAULT = 'default' (use vmx parameter 'backup.session'=name)
-6 set timeout default 60000 ms (1min)
-v set guest to backup using "vm number order"
-F backup host configuration
-C Configuration File (set parameters by file)
-2 Force a dismount before the mount operation
-N create a file with a list of files to backup
-O Only do add redo (without redo commit)
-o Only do commit (without add redo)
-P run command before backup process
-p run command after backup process
-x select guest by vmx file ( es. -x /home/vmware/win2000/win2000.vmx,etc)
-7 use a temporary directory for export (move file after export)
-r force the use of second level of REDO
-Q create a tar.gz file one for each disk inside a unique guest directory
-q create a tar.gz one for each vm guest with inside all owned file
-g create a zip for each vm guest

REMOVED OPTIONS
-V force to handle destination directory like a VMFS volume
-T tar.gz destination file

DESCRIPTION
vmbk.pl is a script for creating ESX disk snapshot.
It supports disk copy to local host disk or remote Disk with NFS / SMB / FTP
vmbk.pl can be used on guest powered or on guest unpowered.
vmbk.pl support batch and interactive use.
vmbk.pl search about 'backup' option on vm guest definition file ,the option may have 4 value NONE , MANUAL , AUTO , ALWAYS if NONE no backup is possible, if MANUAL is possible only interactive mode (-i option) , if AUTO backup is always done.
If backup isn't finding, it's equivalent to AUTO.
You can choose also to set SCSIx:y.BACKUP for permit or not a single disk backup, the value are the same NONE , MANUAL , AUTO
You have also the possibility to define various backup session 
See OPTION IN VMX CONFIGURATION FILE for more info

OPTIONS

-h  Help about parameters
-n  don't display start info
-d directory Exports the disk contents of the specified guest OS on the specified directory local or remote, to a VMware Workstation format virtual disk.
The virtual disk may then be transferred to another machine and imported to a SCSI device on the remote machine.
The virtual disk will likely take less space then the full size of the VMFS file, since the virtual disk does not
include zeroed sectors of the disk image. When this option is used on a guest powered on an ESX Server REDO log is
created, when the exported virtual disk is done the REDO log is commit to its base disk.
REMEMBER FINAL / on directory
 
-n  nfs=host:export[,mountpoint=mountpoint][,options=options] Mount NFS host's export on directory specified by mountpoint, using options value as nfs options (default -soft)
-s smb='host/share'[,user='user name'][,password='password'][,mountpoint=mountpoint][,options=options]
 
Mount SMB host's share on directory specified by mountpoint, if omitted user and password user guest will be used , options pass options to samba
-l logfile Create a text log  logfile
-L logfile Create a HTML log logfile
-y [facility=<facility>],[level=<level>] use syslog to trace events default 'local6' and 'info'
-t Don’t create export file, but done all process
-i Interactive mode
Shows a menu where you may choose what guest do you want export
-a Backup all vm
Override default setting,  backup only started vm.
-f ftp='host',dir='remote directory',user='user name',password='password',
passive='true o false',timeout=<sec>

 
Export dsk to ftp server
-1 use vmdk format for export
Export disk file with vmdk extension
-3 make a backup of redo disk file
When start make a REDO.REDO file and backup DSK + REDO file
-4 backup configuration file (.VMX) and CMOS
-c create restore command on export directory, simply execute the script file on destination directory and follow instruction
-m export disk in flat mode, every dsk file is exported to unique directory
-e smtp='host'[,from='email address'],to='email address'[,encode='encode type'][,html=true|false] send report by email
 
-j value Set minimum allowed free space on destination disk
-z Use cp instead of vmkfstools (copy dsk file)
-5 Set the initial name of backup destination directory (default 'vm-')
-J value Set minimum allowed free space on VMFS for allow creation of REDO, in MB - DEFAULT = 512
-b session name Backup session DEFAULT = 'default' (use vmx parameter 'backup.session'=name)
-T dirtemp Removed
-6 timeout set timeout for every command default 60000 ms (1min)
-v n,m,j,... set guest to backup using "vm number order" separated by comma
-V Removed
-F backup host ESX configuration
-C configurationfile permit to use a configuration file
-2 Force a dismount first of mount operation
-R use vmkfstools (raw mode more faster) instead of cp
-N vmdkfilelist create a list of files to backup
-O Only do add redo (without redo commit)
-o Only do commit (without add redo)
-P run command before backup process
-p run command after backup process
-x <vmx file>,<vmx file>
 
select guest by vmx file ( es. -x /home/vmware/win2000/win2000.vmx,etc)
-B  policy='policyname'[,master='masterserver'][,clientname='clientname'][,logfile='logfile] [,netbackupprepost='true| false'] use Veritas Netbackup see article
-G server='servername',group='groupname'
[,clientname='clientname']
use Legato NetWorker see article

 

-Q create a tar.gz file one for each disk inside a unique guest directory
-q create a tar.gz one for each vm guest with inside all owned file
-g create a zip for each vm guest
-7 <tempdir> use  a temporary directory for export (move file after export)
-r force the use of second level of REDO

 
EXAMPLES
vmbk.pl -d /export/
Backup vm started to /export/ directory

vmbk.pl -d /export/ -a -1
Backup ALL vm to /export/ directory with vmdk extension

vmbk.pl -d /export/ -i
Show menu where you may chose which guest backup

vmbk.pl -d /tmp/ -f ftp=ftpserver,dir=/vmbackup,user=ftpuser,password=ftppassword,passive=false
Backup VM to ftpserver with ftp protocol(passive mode), using /tmp/ directory for temporary file

vmbk.pl -d /vmbk/ -s smb=//smbserver/share,user=smbuser,password=smbpassword
Backup VM to smbserver mounting //smbserver/share on /vmbk/

vmbk.pl -d /vmbk/backup -s smb=//smbserver/share,user=smbuser,password=smbpassword,mountpoint=/vmbk
Backup VM to smbserver mounting //smbserver/share on /vmbk/ and export to /vmbk/backup

vmbk.pl -d /vmbk/ -s smb=//smbserver/share,user=smbuser,password=smbpassword -e smtp=smtpserver,from=esx@vmts.net,to=support@vmts.net
Backup VM to smbserver mounting //smbserver/share on /vmbk/ and send a report by email

vmbk.pl -d /export/ -n srvnfs:/exp -a
Backup ALL vm to exp on server 'srvnfs'
 

vmbk.pl -d /export/vmbk/backup -n nfs=srvnfs:/exp,mountpoint=/export -a
Backup ALL vm to exp on server 'srvnfs' under /export/vmbk/backup mounting srvnfs:/exp on /export dir


vmbk.pl -d /export/ -l /var/logfile.log
Backup all vm switched on to /export/ directory and send output to log file '/var/logfile.log'

vmbk.pl -d /export/ -l /var/logfile.log -v 2,3,7
Backup vm number 2,3,7 to /export/ directory and send output to log file '/var/logfile.log'

vmbk.pl -d /export/ -L /var/logfile.htm -b DataServers
Backup vm with configured 'BACKUP.SESSION = "DataServers"' to /export/ directory and send output to log file '/var/logfile.htm' (html mode)

vmbk.pl  -L /var/logfile.htm -b DataServers -B policy=VMwarePolicy
Backup vm with configured 'BACKUP.SESSION = "DataServers"' to Netbackup master server using VMwarePolicy policy and send output to log file '/var/logfile.htm' (html mode)

vmbk.pl  -l /var/vmbk -b DataServers -G server=LegatoServer,group=VMWare
Backup vm with configured 'BACKUP.SESSION = "DataServers"' to Legato Networker server "LegatoServer"  using VMware group and send output to log file '/var/vmbk' (text mode)


vmbk.pl -d /vmbk/backup -s smb=//smbserver/share,user=smbuser,password=smbpassword,mountpoint=/vmbk -Q
Backup VM to smbserver mounting //smbserver/share on /vmbk/ and export to /vmbk/backup  using tar creating a tar file for each disk + configuration


vmbk.pl -f ftp=ftpserver,dir='/',user=user,password=password,passive=false,timeout=100 -5 %none% -c  -4 -m -q
Backup VM to ftp server put all file (tar.gz format) on same ftp directory / , every file rappresent a VM with inside vmx file, disk , restore file  the name of tar file is the same of guest (no prename)

vmbk.pl  -l /var/vmbk -b DataServers -B policy=VMwarePolicy -y
Backup vm with configured 'BACKUP.SESSION = "DataServers"' to Netbackup master server using VMwarePolicy policy and send output to log file '/var/vmbk'  plus write log also on syslog with facility 'local6' and level 'info'

 


OPTION IN VMX CONFIGURATION FILE

BACKUP = NONE | MANUAL | AUTO | ALWAYS

BACKUP.MODE = REDO | SUSPEND | STOP | SOFTSTOP | SOFTSUSPEND | REDOREDO

SCSIX:Y.BACKUP = NONE | MANUAL | AUTO
where X: guest scsi controller and Y: guest id disk


BACKUP.SESSION = 'name of session'

this guest will be backup only when vmbk.pl has been executed with -b parameters with the same 'name of session'


vmbk-default.conf

#Version 1.01.2
#set timeout
Timeout=60000
#minimum space required for add RedoLOG
minspaceforRedo=1024
#minimum space required for backup
minspace=1024

# backup esx host configuration
backupESX=true

#name of backup session
BackupSession="default"

#directory where file
destination=/vmbk/

#minimum space required for add RedoLOG
minspaceforRedo=1000

#vmbk do not create subdirectory
FlatDir=false
 

#Create a restore shell script
Restore=true

# Backup configuration file and CMOS
BackupVMX=true

# the exported virtual disk contains the redo log if exist
BackREDO=false
#disk format VMDK or DSK
DiskFormat=VMDK
#Backup all Guest
BackupAllGuest=false
#format of log HTML or TEXT
LogFormat=TEXT
#log file an directory with number of day in file name
logfile=/var/log/vmbk.log
 

#use cp command to disk instead of vmkfstools
usecp=false
#use vmkfstool(raw mode more faster than cp. !!!!caution with smb share!!!!)
#command to disk instead of cp
vmkfstoolsrawmode=false

usetar=false
#create a tar.gz one for each vm guest with inside all owned file
usetaronefile=false
#create a zip for each vm guest
usegzip=false

# true or false
email=false
smtpserver=smtp
to=support@vmts.net
from=esx@vmts.net

htmlemail=true

# true or false
forcedismount=false


# true or false
nfs=false
nfsmount=host:/vol

nfsmountpoint=/vmbk
nfsoptions="soft"

 

# true or false
smb=false
smbserver=//smbserver/share
smbuser=domain\\user
smbpasswd=password

smbmountpoint=/vmbk
#smboptions=%none%

# true or false
ftp=false
ftpserver=server
ftpdir="/"
ftpuser=user
ftppasswd=password

# true or false
ftppassive=false
#ftptimeout value expressed in sec
ftptimeout=20


# predirname=%hostname%
# predirname=%date%
# predirname=%time%

# Create a list of fle to backup
backupdisklist=false
backupdisklistfile=/tmp/vmbklist


# only do add redo (without redo commit)
onlyaddredo=false
# only do redo commit (without add redo)
onlyredocommit=false

runonstart=false
runonstartfile=""

runonstop=false
runonstopfile=""


#Netbackup Option
netbackup=false
netbackuppolicy="vmware"
netbackupclientname=%hostname%
netbackuplog="/var/log/vmbk_netbackup.log"
netbackupprepost=false

netbackupmaster="masterserver"

#Networker Legato Options
networker=false
networkerserver="server"
networkergroup="vmware"
networkerclientname=%hostname%
networkerlog="/var/log/vmbk_networker.log"
networkerpool="pool"

#tivoli options
tsm=false

# Use temporary dir
temp=false
tempdir="/tmp"

#syslog
syslog=false
facility="local6"
level="info"

Variable on configuration File

%hostname%  = Hostname
%date% = current date
%time% = Current time
%none% = No value