VMware Cloud Community
ChrisInTexas
Contributor
Contributor

Free ESXi Backup Solution for Windows

I have spent the last few days trying to find a free backup solution to the newly free ESXi for windows only enviroments (in particular Windows XP). The solution for me was the following:

1. Installing Windows Services for UNIX (WSFU)

2. Copying the ESXi Server password and group files to Windows

3. Configuring WSFU for accepting ESX Server connections

4. Sharing the Windows folder for NFS compatibility

5. Configuring the ESXi Server to mount the Window NFS Share as Datastore.

6. Setup Backup Script

Attached is the complete steps.

I take NO credit for any of this. This is just a complation of others work formated to suit my needs and felt others could benift from it as I have.

by Jason Mattox from Vizioncore (direct copy of his work, I just added more information to make it work in Windows XP)

(NFS Server port information)

by robink (The backup script)

(ssh on ESXi)

Tags (3)
0 Kudos
522 Replies
lamw
Community Manager
Community Manager

Hi JoSte,

Oh good catch, I'm sorry yes you're right since we're not snapping an individual VMDK, doh should have seen that. That would be some wasted resources Smiley Wink

I'll update the code and test it out before updating the page. Thanks

Also since we're doing only one snap at a time and vmkfstools copy is only running on one VMDK at a time, the sleep may not be necessarily but let me know if it does help that can be added to systems that are little more constrained and it would be nice to give it smaller breather.

UPDATE: the snippet of code has been tested and the new script has been uploaded, thanks

0 Kudos
kchawk
Contributor
Contributor

I was really trying to avoid the ssh workaround on the host but after trying kpc and lamw scripts the speed increase is more than enough to justify the mod.

I have moded kpc's script to export directly to another datastore under a daily folder. The datastore I use is NFS to an openfiler box. There I offload the backups with my other luns.

I attached the script.

Added the hostname in the path for organization.

Great work everyone.

0 Kudos
lamw
Community Manager
Community Manager

http://communities.vmware.com/docs/DOC-8760 has been updated with new features.

0 Kudos
alubel
Contributor
Contributor

Lamw's script should be kicked off from the ESXi host itself?

How is it kicked off?

oh nevermind.. it worked locally on my esx.. just had to convert file to unix format in notepad++ to get rid of the pesky ^M's

thanks for the script!

-Andy

0 Kudos
blueivy
Contributor
Contributor

Lamw,

This script looks excellent - any chance of having it handle spaces in the VM names (for example I have a VM named 'Monitoring & Maintenance', 'SBS 2003 R2' etc.)?

0 Kudos
lamw
Community Manager
Community Manager

Hi alubel,

Sorry about the the pesky "^M" character, originally I uploaded the file that was created on the ESX host itself, but we assumed most user's may download the file via Windows so we created the example file on Windows (probably bad idea). When opened with notepad the return carriage is not displaying properly and we were afraid that some user's may think the VM_INPUT_FILE should look like the following:

~# cat VM_INPUT_FILE-BAD

 
VM1 VM2 VM3

instead of

~# cat VM_INPUT_FILE-GOOD

 
VM1 
VM2 
VM3

Glad everything is working out.

0 Kudos
JoSte
Contributor
Contributor

@ blueivy:

I have not tested it, but this should do it:

ghettoVCB() {
VM_INPUT=$1
START_TIME=`date`
S_TIME=`date +%s`
{color:#ff0000}IFS=$'\n'
for i in `cat $ | awk 'BEGIN { FS = "\n" } ;{print $1}'`;
do
VM_ID=`grep "$" /tmp/vms_list | awk '{print $1}'`

Alternatively the awk stuff in the for i in ... could be removed. It is redundant anyway. You would need to make sure your input file is exact in that case, however. No trailing spaces or so.

0 Kudos
blueivy
Contributor
Contributor

Hi JoSte,

Thanks very much for jumping in wih a potential solution to this. Much appreciated. However it unfortunately it didn't work for me.

I changed it to (as I think VM_NAME needs to be defined):

ghettoVCB() {
VM_INPUT=$1
START_TIME=`date`
S_TIME=`date +%s`
IFS=$'\n'
for {color:#ff0000}VM_NAME in `cat $ | awk 'BEGIN { FS = "\n" } ;{print $1}'`;
do
VM_ID=`grep "${{color:#ff0000}VM_NAME}" /tmp/vms_list | awk '{print $1}'`

but that gave me the same errors:

Error: Failed to lookup XYZ

(where XYZ is the VM).

I also sometimes get 'Insufficient arguments.'

My VM List file looks like:

SBS 2003 R2 Monitoring & Maintenance

(no trailing spaces etc.)

I wasn't sure what you meant by your comment of removing awk and whether that was from the ORIGNAL script or from yoru modification (I tried removing it from your modification and it didn't work).

0 Kudos
alusrc
Contributor
Contributor

lamw,

kudos for the script it works great. Just looking for some insight though. The crontab changes disappear when we restart the host. How would you schedule this? With RCLI?

Thanks again.

0 Kudos
mvalpreda
Contributor
Contributor

First, thanks for the script khaliss. I think I am getting close to getting this to work.

I am getting an error when running the script

2008-11-24 16:57:20

-


Copy VM files from to <this shows up blank>

-


GET unsuccessful : 404 Not Found

2008-11-24 16:57:25-----

Copy VM files from to <this shows up blank>

-


GET unsuccessful : 404 Not Found

Here is my "configuration"

ESX3i U3 - default everything

Server name: rhea

IP: 192.168.1.6

2 total VMs (for now)

Datastore named: datastore1

Attempting to back up to c:\test

VMWare Infrastructure Client, RLCI and VCB all installed on the server I am running this script on.

I can go to ignore the certificate warning and drill down through the data store tree which brings me to but if I take the errored out line from the script, it just spins and spins and never goes anywhere.

my $url = "https://192.168.1.6:443/sdk/vimService"; #URL to your ESX Host, default: <[https://IP-Address:Port/sdk/vimService]>

my $username = "root"; #Username

my $password = "XXXXX"; #User password

my $snapshotname = "BackupSnap"; #Name of your Snapshot

my $DSPath1 = "[datastore1]"; #Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

#my $DSPath2 = "[datastore2]"; #Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

my @VMNames;

$VMNames[0] = "rhea"; #Uncomment the next lines if you like to backup more vm's

#$VMNames[1] = "";

#$VMNames[2] = "";

#$VMNames[3] = "";

#$VMNames[4] = "";

#$VMNames[5] = "";

#$VMNames[6] = "";

#$VMNames[7] = "";

#$VMNames[8] = "";

#$VMNames[9] = "";

my $RCLIPath = "C:/Progra1/VMware/VMWARE2"; #VI Remote CLI Path (Windows: Use ONLY Short Folder Names!!!!)

my $DestPath = "c:/test/"; #Destination Path you like to copy to; Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

Any help would be greatly appreciated.

0 Kudos
mvalpreda
Contributor
Contributor

Changed my config to:

my $url = "https://192.168.1.6/sdk/vimService"; #URL to your ESX Host, default: <https://IP-Address:Port/sdk/vimService>

my $username = "root"; #Username

my $password = "XXXXX"; #User password

my $snapshotname = "BackupSnap"; #Name of your Snapshot

my $DSPath1 = "[datastore1]"; #Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

#my $DSPath2 = "[datastore2]"; #Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

my @VMNames;

$VMNames[0] = "Windows2000"; #Uncomment the next lines if you like to backup more vm's

$VMNames[1] = "WindowsXP";

#$VMNames[2] = "WindowsXP";

#$VMNames[3] = "";

#$VMNames[4] = "";

#$VMNames[5] = "";

#$VMNames[6] = "";

#$VMNames[7] = "";

#$VMNames[8] = "";

#$VMNames[9] = "";

my $RCLIPath = "C:/Progra1/VMware/VMWARE2"; #VI Remote CLI Path (Windows: Use ONLY Short Folder Names!!!!)

my $DestPath = "c:/test/"; #Destination Path you like to copy to; Datastore name on ESX Host, can be a DAS/SCSI array or a remote NFS share

And now I seem to get further, but I am getting an error in the IC:

A file was not found. /vmfs/volumes/4923daaf-dbc84f48-9d4f-00114333f734/Windows2000/Windows2000-000001.vmdk

And the following error in the script window:

2008-11-24 17:47:09 -


Copy File: Windows2000-000001.vmdk Can't call method "fault_string" without a package or object reference at C:/Progra1/VMware/VMWARE2/bin/vifs.pl line 294.

Not sure if I'm getting closer or not. Smiley Wink

0 Kudos
lamw
Community Manager
Community Manager

Hi alusrc,

Glad you're enjoying the script. I have not had a chance to test the cron backup task on ESXi, but it should be possible. Here are some of your options, I have not had the time to test but if you could report back on what works that would be very helpful to the community.

Due to the limited capability of Busybox which is used to bootup the vmkernel, only "crond" is included and the "crontab" application is not include which is familiar to most to edit crontabs. ESXi actually has a few cron scripts located in /var/spool/cron/crontabs/root

#syntax : minute hour day month dayofweek command
01 01 * * * /sbin/tmpwatch.sh
01 * * * * /sbin/auto-backup.sh #first minute of every hour (run every hour)
00,10,20,30,40,50 * * * * /sbin/decodeSel.sh #Every 10 minutes, translate the latest IPMI SEL data

one of these jobs is actually backing up a subset of configuration files under /etc with the script /sbin/autobackup.sh which calls to /sbin/backup.sh and tarballs the configs to /tmp/local.tgz

Armed with this knowledge you can setup a cronjob for the backup script, but of course the issue at hand is it's not persisting through a reboot. Only the default files are kept.

Currently, our ESXi testing has been using our stateless pxe boot configuration and I have not had time to test out an installed copy and verify some of these findings.

Options:

1) Edit the the crontab manually, then add the following line to /sbin/auto-backup.sh right under the "filestosave" variable

filestosave=`find /etc -follow -type f -name ".#*" | sed 's/\.#\(.*\)/\1/g'`
filestosave="$filestosave /var/spool/cron/crontabs/root"

then manually run a backup (this is done automatically every minute of the hour)

~ # /sbin/auto-backup.sh
Saving current state in /bootbank
Clock updated.
Time: 02:30:58   Date: 11/28/2008   UTC

This should then backup the normal files under /etc and now including the crontab entry and is stored in /tmp/local.tgz, I believe VMware uses this method to allow you to use RCLI to run that backup configuration and this is used to be read back in if a system is rebooted or if you want to upload a backup configuration. I believe if this backup occurs, and the local.tgz is saved on reboot this will be read back in if you have an installed version of ESXi and not running a stateless setup. (this is only an assumption, I haven't spent as much time on ESXi as I would like). If this could be tested and post your findings.

2) The second option is related to stateless boot of ESXi, you have two choices:

a) follow option 1, then use RCLI to backup the configuration file (which will be stored containing local.tgz) and then include that package on your ESXi stateless bootup and the state of the cron entry will always persist through reboots.

b) This is similar to a) but you're actually going to modify environ.tgz which is the actual files that will be laid out on the filesystem: /bin, /dev, /etc, tmp, etc..... you would need to extract this file to setup your stateless ESXi boot anyways, so what you could do a generic or specific customization which allows you to add the cron entry and any other files you would like your ESXi to boot up with. What I've done is include my SSH keys within "/" and enable SSH Console so once the system boots up which is extremely quick, I can ssh right into the system.

I have tested option 2 and I know this will work, but again since I'm using the stateless mode I haven't had the time to test option 1. Hopefully this helps and I would be very interested in peoples findings with option 1 if it's possible. If not then it looks like option 2 or remotely croning the script and executing or uploading the script remotely to run the backup which would work but I would prefer the script sitting on the host itself along with the cron.

Good luck

0 Kudos
JoSte
Contributor
Contributor

@ blueivy:

After I had a second look on that, I think you will have a very hard time to make that script work with spaces in names. The spaces are used by awk to separate fields. While my former code would help with finding a match within the VM list, you still have the problem that many other variables are feed by those awk statements later. They will just not grip the right peaces from the vim-cmd output. My output on the ESXi shows multiple spaces between fields:

Vmid Name File Guest OS Version Annotation

16     test vm   [datastore-1] New Virtual Machine/New Virtual Machine.vmx   winNetStandardGuest   vmx-04

But not sure whether you can rely on that. You could try to separate fields with FS=" +|] "

But not sure if this is really working in every case.

There is also this line:

$ vmsvc/getallvms | awk '{print $1 " " $2 " " $3 " " $4}' > /tmp/vms_list Which would need to be changed! Maybe the whole awk can be removed like this: $ vmsvc/getallvms > /tmp/vms_list

I have not seen any reason why it would be needed. Else you could try:

$ vmsvc/getallvms | awk 'BEGIN{FS=" +|] "};{print $1 ":" $2 ":" $3 ":" $4}' > /tmp/vms_list

and then in all following awk statements use BEGIN{FS=":"}; to separate the fields.

Hope this helps a bit.

0 Kudos
alusrc
Contributor
Contributor

lamw,

Thank you for the quick reply.

Unfortunately it looks like both /sbin/auto-backup.sh and /var/spool/cron/crontab/root are overwritten when we reboot the ESXi host. It looks like the environ.tgz file is the one that contains the /var/spool/cron/crontab/root file in addition to the backup.sh and auto-backup.sh files.

The boot.cfg file in /bootbin is calling this environ.tgz just as in your stateless boot so I'm assuming that's the culprit.

I'm also assuming this file won't persist with a firmware update but will at least stick around through a reboot. My problem is I'm not a linux guy so I don't know how to modify the file and add it to this tgz file. Any advice? My guess is it's as simple as modifying /var/spool/cron/crontab/root and then reinserting it into the tgz while in ESXi, but help would be appreciated.

0 Kudos
kpc
Contributor
Contributor

Not tried this but one workaround based on what Nathan did would be to copy your cron files to a datastore and then edit /etc/rc.local with a simple command that copies the files back into the cron location. Sorry would give an example but not had the time to do any VM stuff recently ....

0 Kudos
lamw
Community Manager
Community Manager

alusrc,

Thanks for the validation of option 1. Then it looks like the only way at least now is through stateless setup or possibly through rc script and copying the crontab on bootup which I'm actually trying to figure out but I think this again relies on the point of modifying the original pristine image from VMware.

To your comment about updating the firmware, depending on the level of the update, you may need or re-work environ.tgz .... but if you use a stateless setup the only file you would care about is the "backup.tgz" which would be included into your boot line, if that's the case then doing an upgrade to the firmware will not affect the state of the file.

There's some documentation on the web on how how to modify those files, but I've also been documenting the process myself for things I've learned while doing this. I have not had free time to finalize the docs but I'll be posting them up in the coming weeks (it's not terribly hard, but yes if you're not use to UNIX/Linux there are few things you'll have to learn).

0 Kudos
lamw
Community Manager
Community Manager

Hi kpc,

Another idea I had looked at but was not able to test due to testing on a stateless ESXi bootup. Easiest way to verify that the /etc/rc.local is persisted through a reboot and ensure there isn't a flat set of default files, just add simple echo statement and make sure its there on the next reboot. If so, then it's a great place to even create your crontab using heredocument or just echoing the line back in the /var/spool/cron/crontabs/root file and restarting the cron daemon.

If anyone could confirm this, it would be great.

0 Kudos
alusrc
Contributor
Contributor

I put a comment in the /etc/rc.local and on reboot my machine had it's configuration changed. the management network IP changed to 0.0.0.0 and now even when I changed it back, I cannot connect with Infrastructure client or even browse to it through web browser. Fortunately this is an empty host we're just trying to figure out this backup process on. I had to run a reset customized settings on the host to get it working again--since I don't know exactly what happened. Of course all of the configuration was lost then.

UPDATE:

I must have done something silly in the rc.local file because I tried it again and everything was fine this time. I just put an echo test in the if statement in rc.local. and after a reboot it was still there. So I guess the next question is how do we edit this to do what we're looking for?

Thanks everyone for all your help. I think a lot of people will get some use out of your work.

Message was edited by: alusrc

0 Kudos
lamw
Community Manager
Community Manager

Hm, that's interesting. I'm wondering if the system checks to see if any of the configuration files have been modified else it defaults to an empty image? I did not know something as simple as an echo statement or comment would cause this to occur, I guess you could have used RCLI to backup the configuration of your host in case it would have done anything unexpected.

So I'm looking at some other files, this may help in the installed version of ESXi:

/etc/init -- here you can see where the "cron daemon" starts up

#start crond
log "Starting crond"
crond

Interesting enough, right before this is where it might be setting one of the cron jobs for the backup

/sbin/configBackup

From this, I think this file should be persisted through a reboot what you could do is add your crontab update right after the line that setups the backup but before the cron daemon is started, so the code would be something like the following:

# Advance the progress bar
esxcfg-advcfg -q -s 1 /Misc/BootProgress

/sbin/configBackup

#add your own cron entries
echo "05 * * * * /ghettoVCBni.sh" >> /var/spool/cron/crontabs/root

#start crond
log "Starting crond"
crond

# Run all configured services
services.sh start

This would just add say the backup script to the cron entry and run every 5min at the hour (change it to whatever you need it to be), and then the cron daemon will fire up and read in the configuration file and your backups should persist on a reboot. Again I have not tested this out, so please test prior to using. Also if you have a live system that you're not sure if any of these changes could affect the system, I would suggest using RCLI or VIMA to backup your ESXi host configuration:

esxcfg-cfgbackup -s myBackUp.tgz

0 Kudos
alusrc
Contributor
Contributor

lamw,

Unfortunately, it looks like /etc/init is rewritten each reboot. I'm thinking kpc might be onto something with rc.local and I just made a mistake earlier. Would I put something similar to your previous post for /etc/init in the rc.local?

0 Kudos