To automatically backup virtual machines on VMWare ESXi host, we are going to use a free tool MKSBackup that can be downloaded here (by the time the article was written, the latest available version of MKSBackup was 1.0.4 as of 24.01. 2013). This tool is a sort of a front end integrated with different backup scripts, including GhettoVCB (a VM backup script written on perl and supported by enthusiasts). GhettoVCB allows to backup running virtual machines online. A VM backup is created by making its snapshot.
MKSBackup is one of a few backup tools that allows to perform online backups of running virtual machines. MKSBackup can be used to back up virtual machines running both proprietary versions of VMware ESXi or free VMware Hypervisor. The tool is developed on Python and is a cross-platform utility and doesn’t have a graphic interface, runs from the command line and can be configured via configuration files.
[accordion]
[tab title=”Contents of this article”]
[/tab]
[/accordion]
It’s obvious that the convenience and manageability of the MKSBackup solution for VMWare virtual machines is less than the proprietary products suggest, but it is compensated by being free, simple to configure and deployment speed.
MKSBackup Script Installation
- Download the MKSBackup archive and extract it.
- Run mksbackup.exe. A simple console installation wizard is started. During the installation you have to specify the directory to which the script is installed (by default, C:\Magik), the necessity to install ghettoVCB script (yes), the name of the backup task (you can do it later) and the user password to run the backup task (can be done later).
Configure Backup Settings of the ESXi Virtual Machines
The next step is to configure the backup settings of the virtual machines running on ESXi. The configuration is basically the editing of mksbackup.ini config file (by default it is located in C:\Magik).
Open mksbackup.ini in any text editor. This file consists of several sections, and the name of each section is enclosed inside square brackets.
Section:
1 | [DEFAULT] |
This section allows to set e-mail notification options. We don’t need them, so we leave:
1 | mail=no |
The next section is [VMWARE_FROM_WINDOWS]. This section allows to set backup options and describes different settings running the virtual machine backup in Windows. In our sample the task looks like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [VMWARE_FROM_WINDOWS] program=ghettovcb host=10.1.1.89 port=22 login=root password=L4&43fdc463 local=C:\magik\vmware global_conf=ghettoVCB.conf vm_list=vm1 winXP destination=C:\magik\${vm} scp_bin="C:\Tools\Putty\pscp.exe" -scp -r |
Let’s consider the task settings in more detail:
program – a backup program, we leave ghettovcb
host – a name/IP of the ESXi host, on which virtual machines are running
port – an access port (by default, port 22 — SSH protocol)
login – a name of the user having access rights to the ESXi server (by default, it is root, but for the reasons of safety it’s better to create a separate user on the ESXi server)
password – a user password
local – the local directory, where a backup script and its configuration is stored
global_conf – a file containing ghettoVCB settings
vm_list – a list of virtual machines subject to backup. If you need to back up all virtual machines, leave this setting empty. If you have to exclude some VMs, use the vm_exclude parameter.
destination – this option allows to specify the type of an operation. It can be
- backup – performs a simple backup (you don’t have to specify destination)
- copy – performs a backup and copies the backup files into the specified folder
- move – performs a backup and moves the backup files into the specified folder
Let’s dwell on move as the optimum option. In this case local backups of virtual machines are created on the ESXi host, then they are moved to the computer that has run the script.
mon-sun – it is assumed that the script can be run daily (let’s leave it as it is, because we set the backup interval in the Windows Task Scheduler).
In addition, specify the folder, to which VM backups will be moved (C:\magik). The ${vm}parameter shows that each virtual machine will get a separate directory with the name of this machine to store the backup files.
Note. A detailed description of configuration settings of the script and its synax is given on the developer web site.
scp_bin – a path to scp utility
Then it is necessary to make some changes to ghettoVCB.conf (in our example it is located in C:\magik\vmware). We need the following options:
1 2 3 | VM_BACKUP_VOLUME=/vmfs/volumes/eva6400/backup VM_BACKUP_ROTATION_COUNT=3 |
VM_BACKUP_VOLUME is the directory on the ESXi server where virtual machine backups will be stored (it’s obvious that VMFS should have enough free space)
VM_BACKUP_ROTATION_COUNT is a number of stored local copies (in our example the latest 3 copies will be stored)
Now you have to save a host key in the local SSH cache with the plink utility (a part of Putty package). E. g., like that:
1 | PLINK.EXE root@10.1.1.89 ls / |
Starting backup of virtual machines on the VMWare ESXi
Let’s test the backup script. To do it, open the command line with administrator privileges and run the command:
1 | C:\Magik\MKSBackup\mksbackup.exe -v -c C:\Magik\mksbackup.ini backup VMWARE_FROM_WINDOWS |
,where –v shows that verbose information is displayed, -c specifies the path to the configuration file mksbackup.ini, backup means that backup should be run, at the end a name of the task from mksbackup.ini (in our sample it is VMWARE_FROM_WINDOWS) is indicated.
If everything is configured correctly, the tool starts to display verbose information about the backup progress in the console (the backup process is quite time consuming, so it wouldn’t end quickly).
The backup progress can be tracked by appearing/deleting snapshots in VMware vSphere console.
During script execution the folders containing virtual machine files will appear in the destination directory.
After test backup you can proceed with automatic backup. To do it, create a new task in the Windows Task Scheduler.
Create a task with the name «Backup ESXi», which is performed on Friday and runs the command: C:\Magik\MKSBackup\mksbackup.exe -v -c C:\Magik\mksbackup.ini backup VMWARE_FROM_WINDOWS
Don’t forget to specify that the task should be run with administrator rights («Run with highest privileges») in the task options.
The disadvantages of this method of virtual machines backup are:
- rather low speed of backup
- much free space necessary to store VM backups
These disadvantages are compensated by the fact that it is free, but it’s better to use paid backup products for larger solutions, like Veeam or HP DataProtector.