Thursday, December 3, 2009

how to backup vmware esx 4.0 virtual machines for free

If you are running a vmware esx 4.0 and has deployed a number of virtual machines. There will come a time that you're gonna think on how to backup your virtual machines for free. If you have the budget then you can just purchase third party backup solutions. It will make your life easy. But if you are on a tight budget you might as well take time to read this short how-to. This how-to is done using VMWARE esxi 4.0 and ReadyNas as backup storage of all my VMs. Ok enough lets start with the procedure.

1. Make sure that you have enabled ssh in you vmware server. If you haven't you can refer to the link below on how to enable ssh access. The link below refers to vmware esx 3i but will work on esx 4.0

http://www.vm-help.com/esx/esx3i/ESXi_enable_SSH.php

2. Once you have gained access to your vmware server you need will need a script for creating backups and restoring your virtual machines.

Scripts Download link

a. Backup - ghettoVCB.sh

b. Restore - ghettoVCB-restore.sh

3. I neeed to place all my backup on a remote location so I need to create a datastore in my vsphere client. To do that (you can also mount the NFS share on your remote storage using CLI)
Make sure you have enabled NFS in you remote storage (readynas NV+) in my case.

a. Login to your vmsphere and click on the host.
b. Go to configuration and click on storage
c. Click on add storage and choose "Network File System"
d. Fill up all the required fields for you to mount the remote storage.
e. Once mounted successfully you will see a new datastore

4. Ok so we have mounted our NFS remote storage and with this we will now be able to access the remote storage from our console (CLI)

5. Its time to make backup. Go to the directory in your ESX Server where you have downloaded the backup and restore script.

6. You need to get the path of the mounted remote storage to do that you need to navigate to the folders inside /vmfs/volumes in your vmware server.

7. Once you have the path you need to edit "ghettoVCB.sh" and look for the line "VM_BACKUP_VOLUME=" put the exact path of your remote storage after the = sign.

8. we need to create a flat file that will list the names of our virtual machines. Just create a file and list all the names of your virtual machines. 1 VM per line. ex.

vi vm_to_backup

virtual_machine_1
virtual_machine_2

Make sure that you list the exact name of your virtual machines in the flat file.

9. Once you have the file its time to create the backup. To run the backup you need to issue the following command.

"./ghettoVCB.sh -f [filename of your flatfile]" ex. "./ghettoVCB.sh -f vm_to_backup

10. It will now start the backup. I suggest you run your backups during off peak hours to avoid high CPU utilization. In my case I run my backup every weekend at 12 MD where there are no users.

My next post will be on how to restore you VMs. Hope this will be able to help you. Leave your comments for clarification.