Showing posts with label vmware. Show all posts
Showing posts with label vmware. Show all posts

Friday, June 26, 2009

Backing up VMWare ESX 3.5

I'd been whining about the troubles I had getting the various parts of a VMWare backup script working. Well, I've got something that appears to fill the bill.

The end result is that I have a backup local to the host, so I can restore very quickly, and as many past snapshots as my Windows server can hold.

The first thing you need to do is open up the firewall:
esxcfg-firewall --enableService smbClient

Note that in order for everything to work, I have to use the FQDN to the server. Otherwise, I'd get an error regarding broadcasts.

Here's the main script:
#!/bin/sh

VMCONFIGLIST=`/usr/bin/vmware-cmd -l`
TODAY=`date +%Y%m%d`
BACKUPBASE=/vmfs/volumes/`hostname`\:raid0/backups

USER=root
PASSWORD=nunyabidnz

WINUSER=NA/meh
WINPW=blah
WINDEST='//server01.example.com/backups'

if [ ! -d ${BACKUPBASE} ]
then
echo "Backup directory ${BACKUPBASE} does not exist."
echo "Exiting"
# no, I don't want to create it. If there's a problem with the path,
# there's no telling where these backups will end up.
exit
fi

echo "Back up for ${TODAY}"
echo "Backup directory ${BACKUPBASE}"

for VM in ${VMCONFIGLIST}
do
# set up the variables for this loop
VMDIR=`dirname ${VM}`
echo "Looking for ${VMNAME} in ${VMDIR}"

# if the config file doesn't exist, we can't do anything
if [ ! -f ${VM} ]
then
echo " * Did not find ${VM}."
echo " * Skipping"
continue
fi

# get the VM name from the config file
VMNAME=`cat ${VM} | awk '/displayName =/ {print $3}' | sed 's/\"//g'`

DESTDIR=${BACKUPBASE}/${VMNAME}

TARNAME=${VMNAME}.${TODAY}.tgz

# the work begins here
# all the configurable stuff should be above this line

echo " - Backing up ${VMNAME}"
echo " - file ${VM}"

# vcbMounter bombs out if the directory already exists
if [ -d ${DESTDIR} ]
then
echo " - deleting directory ${DESTDIR}"
rm -Rf ${DESTDIR}
fi

# create the backup
echo " - Starting vcb..."
/usr/sbin/vcbMounter -h `hostname` -t fullvm -u ${USER} -p ${PASSWORD} -r ${DESTDIR} -a Name:${VMNAME}

# check vcbMounter's return
if [ "$?" -ne "0" ]
then
echo " - Error backing up VM ${VMNAME}"
continue
else
echo " - Successful backup of ${VMNAME}"
fi

# compress it

echo " - Archiving backup to tarfile ${BACKUPBASE}/${TARNAME}"
echo " - to tarfile $TARNAME"
# --force-local to ignore the ":" in the path
tar -C ${BACKUPBASE} --force-local -czf ${BACKUPBASE}/${TARNAME} ${DESTDIR}
echo " - Compression completed"

echo " - Copying to ${WINDEST}"
/usr/bin/smbclient -c "prompt off; put ${BACKUPBASE}/${TARNAME} ${TARNAME}" -U ${WINUSER} ${WINDEST} ${WINPW}

echo "Cleaning up .tgz"
rm -f ${BACKUPBASE}/${TARNAME}

echo " --- ${VMNAME} complete --- "
done

Any suggestions for improvements (how about an occasional function , Mr. Goon? Or check the return from smbclient? Hmmm?) are welcome.

Monday, June 22, 2009

vmware-cmd Not Working

I'm still working on those VM backups. I got everything started okay on the first node. It wasn't until the second node that I ran into other problems. Of course.

Attempting to run vmware-cmd resulted in the following:

Can't locate VMware/VmPerl.pm in @INC (@INC contains: blib/arch -Iblib/lib -I/usr/lib/perl5/5.6.0/i386-linux -I/usr/lib/perl5/5.6.0 -I. /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 . blib/arch blib/lib /usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0 .) at /usr/bin/vmware-cmd line 133.
/usr/bin/vmware-cmd requires the VMware::VmPerl Perl libraries to be installed.
Check that your installation did not encounter errors.

According to some stuff I found, this can be caused by clock-skew when the server is installed. Of course, I don't care about why it happened (just good to know). How to fix it?
# vmware-config.pl

Please specify a port for remote console connections to use [902]

Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
Configuring the VMware VmPerl Scripting API.

Building the VMware VmPerl Scripting API.

Using compiler "/usr/bin/gcc". Use environment variable CC to override.

Installing the VMware VmPerl Scripting API.

The installation of the VMware VmPerl Scripting API succeeded.

The configuration of VMware ESX Server 3.5.0 build-123630 for this running
kernel completed successfully.
And that cleared it up.

smbclient Woes on ESX

I'm writing a backup script for our ESX hosts, and I ran into a problem connecting to the Windows server.

After opening the firewall with
esxcfg-firewall -e smbclient

I still got an error attempting to connect to the Windows machine:

[root@ESX backups]# smbclient -U DOM\\adminusers //server01/backups password
Packet send failed to 10.4.136.255(137) ERRNO=Operation not permitted
Connection to server01 failed

Okay, so the firewall is blocking broadcasts (that ".255" at the end). The solution was to negate the need for the broadcast. smbclient was unable to resolve the IP address given just the hostname of "server01", and was attempting a netbios broadcast (I think).

The solution was to use the FQDN to server:

[root@ESX backups]# smbclient -U DOM\\adminuser //server01.example.com/backups password
Domain=[DOM] OS=[Windows Server (R) 2008 Enterprise 6001 Service Pack 1] Server=[Windows Server (R) 2008 Enterprise 6.0]
smb: \>