Automating VMWare ESXi snapshots through Scheduled Tasks

July 7th, 2009

Earlier I wrote about Creating ESXi snapshot backups with ghettoVCB.sh. Now, the next logical step is to be able to automate these snapshots so you don’t need to ssh to the ESXi host and run the script manually and wait for the result.

We can use plink, and Windows Scheduled tasks to achieve this result.

In order to use Plink, the file plink.exe will need either to be on your PATH or in your current directory. To add the directory containing Plink to your PATH environment variable.

Start -> Control Panel -> System -> Advanced -> Environmental Settings -> System Variables -> Path -> Edit, and enter the path for your plink.exe file.

OK, so once plink is setup correctly, you can use the following command to connect to your ESXi host, and set your script running with the appropriate ‘vmbackups’ file for the relevant machine.

E:\backup\putty\plink.exe [email protected] -pw passsword “nohup /vmfs/volumes/datastore1/scripts/ghettoVCB.sh /vmfs/volumes/datastore1/scripts/vmbackupsbuilder > /vmfs/volumes/datastore1/scripts/backuplog.txt &”

Picking the above command apart:

1. E:\backup\putty\plink.exe (the path to plink.exe)

2. [email protected] -pw passsword (the username, IP address and password of your ESXi Host)

3. “nohup /vmfs/volumes/datastore1/scripts/ghettoVCB.sh /vmfs/volumes/datastore1/scripts/vmbackupsbuilder > /vmfs/volumes/datastore1/scripts/backuplog.txt &” (this is the path to your ghettoVCB.sh file, the path to your vmbackups file, and a command to log the output

We also run this as a ‘nohup’ command so that the snapshot can continue without anyone being continuously logged into the host.

You probably want to run this without the nohup as a first test, to make sure everything is working OK.

Once you’re happy with the command and it runs successfully for you, you can simply add this command to a .bat file, and then use the standard Windows Task Manager to schedule it to run as frequently as you wish.

Creating ESXi snapshot backups with ghettoVCB.sh

July 2nd, 2009

This is the second post in a series regarding the backup of ESXi Virtual Machines.  Once you’ve got ssh and ftp access sorted you’ll be able to connect remotely to the ESXi host and run scripts (which use the ESXi command line) to automate certain tasks.

One of the best scripts out there for backing up ESXi hosts is called ghetto.vcb You can find out more about the script here:

http://communities.vmware.com/docs/DOC-8760

So, here’s how to set this up

Stage 2 – implementing the ghettoVCB.sh script.

1. First of all, download the ghettoVCB.sh script, and the example file vmbackup

2. Now, you’ll need to ftp these files to you ESXi host (If you haven’t already enabled ftp access, you can find my guide on how to do it here http://www.rancidswan.com/?p=4)

3. Now, ssh to your ESXi host and edit the ghettoVCB.sh file. There are a number of options at the top of the file, but not many, and they should all be fairly self explanatory. Just for testing you can set the path of the backup location to be somewhere on the ESXi host itself. Later I’ll be writing a guide on how to setup an NFS share on a Windows 2003 server so that these snapshot backups can be pushed directly to a windows machine.

4. You’ll also need to edit the file I’ve called vmbackup. This file purely contains just the name of the machine you want to backup (note: it’s the machine’s Virtual Machine name, not it’s Computer name you use, the name has to be understandable by the ESXi host)  You can have multiple machine names if you wish, with distinct names on each line, but personally I’d recommend just having one name in the file, this will make it easier to automate individual machine backups later on)

5. OK, now you’ll need to set the permissions on the file ghettoVCB.sh like this:

chmod 777 ghettoVCB.sh

5. Now, to run the script, you simply need to write:

./ghettoVCB.sh vmbackups

The script will now run and either show a progress meter, or show you any error messages you might need to tackle!

Enabling ssh and ftp access to your ESXi host.

June 29th, 2009

This will be the first of  a series of posts regarding the backup of ESXi Virtual Machines from an ESXi host. This will probably take four or five seperate blogs to explain.

Stage 1 – Enabling ssh and ftp access on your ESXi host.

The default setting for any ESXi host is to have ssh and ftp access disabled, not great for administering the box.  To enable it:

Once the machine has booted, press ALT + F1

type: unsupported (this text will not be displayed, if you make a mistake CTRL + U clears the input)

now you will need to enter the root password.

  1. At the prompt type “vi /etc/inetd.conf”
  2. Look for the line that starts with “#ssh” and “#ftp” (you can search with pressing “/”)
  3. Remove the “#” in both places (press the “x” if the cursor is on the character)
  4. Save “/etc/inetd.conf” by typing “:wq!”
  5. Restart the management service “/sbin/services.sh restart”

The Management Service will now restart (takes a couple of mins)

Now you need to kill the inetd service;

  1. ps -a | grep inetd
  2. kill (# of inetd service)
  3. inetd

Press Alt+F2 to return the server to DCUI mode.

Voila! You can now use your favourite ssh client to access the ESXi host.