Bacula-users

Re: [Bacula-users] bacula to backup vmware images

2008-08-15 04:08:48
Subject: Re: [Bacula-users] bacula to backup vmware images
From: Ronald Buder <rbuder AT proficom-ag DOT de>
To: Lukasz Szybalski <szybalski AT gmail DOT com>
Date: Fri, 15 Aug 2008 10:08:18 +0200 (CEST)
Hi,

as I don't seem to get around to testing with a VMware Server, I'll just
share my ESX scripts with you... maybe they help, at least as far as
understanding goes.

Ok, here goes:

#!/bin/sh

# Backup of a single VM using VCB
# first parameter is an identifier, such as the VM's name inside ESX or
it's IP (the latter one works with running VMware tools only):

VM=$1
exportbase=/localdata/bacula
exportdir=$exportbase/$VM/$(date +"%Y%m%d-%H%M")
mkdir -p $exportbase/$VM
/usr/sbin/vcbMounter -a ipaddr:$VM -r $exportdir                    #
this is the part where the actual work is done
cd $exportdir
if [ $? = 0 ]
then
 echo "Backup successfull..."
 exit 0
else
 echo "Directory missing, backup failed..."
 exit 1
fi

The script really isn't hard. I have a wrapper script which calls this
one repeatedly. The wrapper script determines the VM's to be saved (I
spread them across the week in order to keep the load down a bit, 27 VMs
at the moment, I keep the time the VM was last saved in a database
table, alter it slightly using a simple random function in order to have
it spread chaotically). The script itself is being run directly on our
dedicated backup ESX host, the wrapper script is bacically a perl
application which runs directly on the bacula director and calls this
one via ssh with key login enabled. So no need for passwords here...

There is a second script however which works slightly different. It's
not being called by Bacula at the moment, it runs within our old backup
system. The goal to the second script was to save every VM on two
dedicated ESX hosts.

Here goes:

#!/bin/bash
echo "Script to automatically backup RTL vms"

for host in 10.92.79.48 10.92.79.58
do
       ssh root@$host << EOF
       mount 10.92.79.25:/localdata/rtl /mnt/backup
       EXPORTBASE=/mnt/backup
       for i in \`vmware-cmd -l\`
       do
               VM_NAME=\`grep displayName \$i | awk '{print \$3}'\`
               VM_NAME=\`echo \${VM_NAME%?} | sed "s/^.//"\`
               EXPORTDIR=\$EXPORTBASE/\$VM_NAME/\$(date +"%Y%m%d-%H%M")
               echo "VM \$VM_NAME wird nach \$EXPORTDIR exportiert"
               mkdir -p \$EXPORTBASE/\$VM_NAME
               vcbMounter -h localhost -u root -p VerySecurePassword -a
name:"\$VM_NAME" -r \$EXPORTDIR
       done
       sleep 10
       umount -l /mnt/backup
EOF
done
exit 0

Not very elegant, I know. Again the part that does the actual work is
the vcbMounter line. This one basically logs into the first ESX host,
uses vmware-cmd -l to get the VMs running on that host and then starts
exporting them one by one. Once through, we log into the second host and
do the same thing. This is somewhat nessary as we run plenty of ESX
hosts having DRS enabled so you can never be sure just where a VM
currently resides. The backup itself runs directly onto a nfs share, as
you can see.

Anyways, hope that helped. Questions welcome, suggestions also :)

Regards, Ronald


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users