I’m a massive fan of VMWare products. I use the excellent VMWare workstation for most of my development on the desktop, and I use VMWare ESXi (3.5) for hosting my virtual servers.
VMWare ESXi is a truly fantastic product, and it is free, but with this free version you are limited in the management toolset available. One thing that is missing is an easy way to back up your VMs.
Over time, I’ve tried a few approaches to backing up – none really good enough:
- Using the download option in the "datastore browser". Not reliable for large files, and most of my VMs are > 30GB
- Enabling ssh in the VMWare ESXi hypervisor, and using SCP to download the vm files. Again, not reliable for large files
- Using the “VMWare vCenter Converter Standalone” to copy/convert my VMs to local copies. This is often slow though, and I don’t really understand what aspect of my VMs are being "converted", and to what. In short, I don’t really understand what is happening and if it might impact the stability or performance of any restored VMs, so I am nervous about it.
- I’ve investigated and given up on trying to get smbfs support running in the hypervisor shell. The idea here was to allow me to mount a remote Windows share, and just copy the vm files over. However, no smbfs support built in. No installer mechanism (e.g. no rpm and no apt-get), no compiler and no iso9660 support that would let me at least mount a cd-rom. This hypervisor is thin!
- I tried using a Ubuntu 9.04 live CD, so I could start up the ESXi host machine in Ubuntu (of course, it means ESXi VM host server would not be available during this time), but then realised there was no vmfs support in Ubuntu so I wouldn’t be able to mount the disks containing the VMs.
All is not lost though; ESXi does support NFS natively (as a client), so it is relatively easy to create an NFS "backup share" on another server
One thing worthy of note – I have tried creating an NFS server on my Windows XP box (using Windows Services for UNIX 3.0) and on my Windows 2008 server (using Services for Network File System). In both cases I could not get ESXi to play nice with the share, so I switched back to using Linux to host my NFS server. Right tool, right job, and all that.
My setup will be this – a VM running Ubuntu (10.04) which exports an NFS share that can be used to copy the backup VM files to and from ESXi (from within the ESXi shell). Optionally (and beyond the scope of this article), this exported directory can also be shared out via Samba, to give your Windows clients access to the backed up files.
These notes are a list of how I did this specifically. Your mileage may vary:
Initial setup of your Ubuntu environment
- Install Ubuntu (10.04) to a VM, a physical box, or somewhere.
- Make sure you have plenty of disk space to host the backups on, and create your target shared directory. For this example I’ll be using /backups
- Set the permissions accordingly on this directory
Installing NFS and exporting your share
- Install your NFS server:
sudo apt-get install portmap nfs-kernel-server
- Export your shared directory by editing /etc/exports and adding the following (noting that 192.168.0.1 should be replaced by the ip address of your ESXi server):
- Issue the command
sudo exportfs -ra
- Start/Restart the NFS service by issuing the command:
sudo /etc/init.d/nfs-kernel-server restart
- You should now have an exported NFS share!
Mounting your NFS share from ESXi
- Start up the VMWare Infrastructure client and log into your ESXi server
- Select Configuration->Storage and choose "Add Storage"
- Choose "Network File System"
- For the "server", enter the IP address of your Ubuntu server
- For the "folder", enter the full path to the exported folder: /backups
- For the "datastore name", enter a meaningful name, e.g. nfsshare
- You should now be able to see the remote NFS share from the ESXi host.
Backing up your VM
I prefer to perform this step from the command line rather than using the VMWare Infrastructure Client. Again, your mileage may vary.
- Log onto your VM console by hitting <ctrl>-<alt>-F1 at the VMWare splash screen, typing "unsupported" (without the quotes) and hitting return, and then entering your password.
- Move to the volumes directory with
- Note that this directory contains subdirectories of the physical drives, and the NFS share
- Ensuring the power is off on the VM you are about to back up, copy the VMs directory to the NFS share. For example:
cp Disk2/MyVM nfsshare -R
- Check the folder has been copied to the target share, et voila – you have a backup of your VM
Restoring your VM
Again, I prefer to perform this step from the command line rather than using the VMWare Infrastructure Client. This is the same approach as backing up, except that we copy the files from the NFS share to the ESXi server. In other words, the last step becomes something like:
cp Disk2/MyVM nfsshare -R
Finally, you may need to re-import the restored VM into the ESXi host’s inventory. To do this, navigate to the VMs files in the VMWare Infrastructure Client, right click on the VMs .vmx file, and click "Add To Inventory"