Creating Virtual Machine Backups in VMware with GhettoVCB
Hi folks, like I mentioned before I’ll be showing you how to create backups using the GhettoVCB script from William Lam. First things first, please enable SSH access on your ESXi box. You can do this by following my steps in my previous blog post.
Next, you have to download the following software for use on your computer to help you get this all accomplished.
- Putty.exe (This is one of the more famous SSH programs out there used to connect to the ESXi server via SSH)
- Plink.exe (This is used to run command line commands in your SSH session with the ESX server, this is integral for scheduling scripts)
- WinSCP (This program is used to upload and download files between your ESXi server and your workstation)
After you have downloaded these programs, please install them on your workstation. Then you can go and download the ghettoVCB.sh script from the VMware communities web site where this script is hosted at.
After you have downloaded the script, do not edit it on a Windows computer otherwise you run the risk of introducing control characters into the script which will cause the script to fail when run on the ESXi server. Instead, just upload the script to your ESXi server using WinSCP. Please ensure that you change the transfer settings mode to text mode for the transfer.
After you have transferred the script up to the ESXi server please ensure you move the script into your /vmfs/volumes/Datastore1 directory. There is a good reason for this. If you do not move it into your datastore directory the script will be erased the next time you reboot the ESXi server. The ESXi server will not erase anything stored in the VMFS datastore however. Your datastore might have a different name than mine so just make sure you put it in your datastore that you created when you installed ESXi.
After you have copied the script to this folder, create a new text file named whatever you want that contains a list of the virtual machine names as they are listed in your VMware client when you connect to your server. For example if you have three servers DC01, DC02, EXCHANGE01, then put those three names in the data file. You can create a data file in ESXi by doing the following, I am going to use the filename vmbackups for my example. First change directory to your datastore volume before creating the file. Keep in mind that everything is case sensitive.
- Type the following at the command prompt in your ESXi ssh session:
- cd /vmfs/volumes/Datastore1
- Type in: vi vmbackups
- Hit the insert key to enter editing mode in vi. Type in DC01, hit enter, type in DC02 hit enter, type in EXCHANGE01, and hit enter.
- Hit escape to exit editing mode.
- Type in a colon “:” and then type wq and hit enter, this will save the file and quit back to the command prompt.
There, now you have created your data file that contains the names of your virtual servers. Remember that this is case sensitive so if you typed in dc01 and your server’s actual name in the VMware client list is DC01 then it won’t work when the script runs.
Now you need to choose a location to store your backups too. You could just save your backups to your datastore and then manually use WinSCP to save them off everyday. Or you can mount an NFS share and have your backups save to that NFS location. The best way to do this is to install Windows Services for Unix version 3.5. Please follow the directions here on how to do this.
If you don’t have a Windows server with storage available for this then you could use a Windows workstation with a 3rd party NFS product to share out a drive. My own personal favourite is Allegro NFS. I am currently trialing the software and will probably purchase it for use in my test lab at home. I use it on my Vista machine at home where I have a USB external hard drive attached to it. Allegro NFS allows me to share out a folder on my USB drive and make it available to my ESX server. I have created a folder called vmwarebackups and shared it out using NFS. The NFS pathname is /x/vmwarebackups. Let’s say for example that my computer’s IP address is 192.168.2.10. Now what I need to do is connect to the ESXi server with my VMware client and add new storage.
- Do the following:
- Go to the configuration tab in the VMware client after highlighting your ESXi server. Click on the storage link under Hardware. Then click on the add storage link.
- Select Network File System from the options presented to you and click next
- In the Server field type in the IP address of the server that is hosting the NFS share, in my example it would be 192.168.2.10
- In the folder field type in the NFS folder name. With most products the folder naming convention will be the drive letter first and then the share name. If you are using Windows Services for Unix it will probably just be the share name. On my Vista machine my external drive is the X drive and the share is VMware backups. So the NFS path is /x/vmwarebackups and that is what I would type in this field. If I was on a Windows 2003 server using Windows Services for Unix and shared out the same share the path would just be /vmwarebackups and then that’s what I would type into the field
- Type in a name for the datastore, you can call it whatever you want. For example I will name it backup and then click next. Do not select the mount NFS As read only option.
- Then finish off the wizard by clicking finish and you’re done. You will now notice you have a new piece of storage called backup listed under storage.
- You can now test to see if the path exists by changing directory to it in an SSH session. Type in cd /vmfs/volumes/backup and that should switch you into that directory. Then try and create a file in that directory or make a new directory with the mkdir test command and it should create a folder for you called test. If this works, then this verifies for you that you have write access to this share.
Now you need to edit the script and change the options to suit your tastes. The way you edit the script is as follows:
Edit ghettoVCB.sh by typing in vi ghettoVCB.sh while you’re in the directory where you moved ghettoVCB.sh
Edit the following lines in the script, the script is nicely commented to let you know how to set up the parameters
- VM_BACKUP_VOLUME=/vmfs/volumes/backup (this is the path of your NFS share)
- ENABLE_2GB_SPARSE=0 (set this to 1 if you want to split your VMDK into 2 GB files)
- VM_BACKUP_ROTATION_COUNT=3 (Number of backups you want to keep before it deletes old ones)
- VM_BACKUP_DIR_NAMING_CONVENTION (I just leave this as is, it’s fine the way the default is setup)
- POWER_VM_DOWN_BEFORE_BACKUP=0 (I change this to 0 so I can do a live backup without shutting down the virtual server)
- ENABLE_HARD_POWER_OFF=0 (I change this to 0 to disable hard power offs)
- ITER_TO_WAIT_SHUTDOWN=4 (I leave this as is, it’s not applicable in our case since we’re not using hard power offs)
After setting this all up then you can save the ghettoVCB.sh script file and now you’re ready to run it. From the ghettoVCB.sh directory type in: ./ghettoVCB.sh vmbackups (this will run the script with the input file list of your virtual machines) and the backup will run and present to you a percentage progress counter as it backs up your virtual machines. You will notice that the counter will count fairly slow. Backing up to NFS is never a quick thing so keep that in mind and have patience.
The script will fail if you made any errors in the input file in regards to case sensitivity and it will also fail if there are any errors with the way you mounted your NFS share. In a future blog I will cover how to properly configure Windows services fo Unix to mount an NFS share.
You will remember that I asked you to download plink.exe previously. This is what you will use to create a Windows scheduled task that will log into the server and execute the ghettoVCB.sh script. In my next blog entry I will show you how to create this scheduled task.