Re: [Bacula-users] bacula to backup vmware images
2008-08-15 04:47:03
James Cort wrote:
> Lukasz Szybalski wrote:
>
>> In vmware server 1.0x ! Providing scripts would be great!
>>
>> - How do I create a snopshat via somekind of script?
>> - How do I put "database into a consistent (sleep) state "
>> - This will export " vmdk-files" That get backed up by bacula? Correct?
>> - Is that all?
>> - How do I restore the whole vmware in case of system crash?
>> - DB vmware needs to be shut down correct? (I saw some stop/start
>> scripts on google, Is there something specific that they need to do
>>
These could be of some use to you
http://fedorasolved.org/Members/scott_glaser/vmware-backup-scripts/?searchterm=vmware%20backup
, I have to do the same so could you let me know how you get on?
Cheers
Keith
>
> I only just noticed this one, but I backup whole VMs using bacula in the
> following fashion:
>
> - VMWare machines are all stored in an LVM volume which is part of a VG
> with a certain amount of free space.
> - All virtual machines in a subdirectory called FullBackupVMs are
> subject to being backed up in full. The only "configuration" the script
> needs is that you need to ensure that any VMs which are to be fully
> backed up reside in a subdirectory of /home/vmware/FullBackupVMs and
> that all virtual disks they use are stored as files on the same LV.
> - Broadly speaking, the backup process consists of:
>
> 1. Pause every VM.
> 2. Snapshot the logical volume.
> 3. Mount the LV snapshot
> 4. Restart every VM.
> 5. Let bacula backup the LV snapshot.
> 6. A post-backup script umounts and lvremove's the snapshot.
>
> This has the minor drawback that every VM needs to be paused as part of
> the backup process - but the snapshots generated by VMWare server are
> binary deltas of things which have changed since the user clicked
> "snapshot" so unless the backup process itself is instantaneous and
> accounts for any data which may be in flight to the disk at the point
> you either run the backup or create an LV snapshot of the VM, there's no
> way you can guarantee you'll be able to go back to a snapshot.
>
> Naturally this does introduce some risk - you may come in in the morning
> and find that all your systems are in a paused state and have been for
> some time. Myself, I only have systems stored in FullBackupVMs where
> there's little point in backing up only a handful of files because if
> the virtual server goes wrong it'll need to be restored in its entirety
> and where I can live with the virtual server being paused for some time.
>
> Restoring is a case of "restore snapshot, import VM into VMWare, unpause
> VM".
>
> A (slightly redacted) version of the pre-backup script which does steps
> 1-4 above follows:
>
>
> LV_SNAPSHOT=vmware-snapshot
> LV=vmware
> VG=sysvg
> FULLBACKUPLOCATION="/home/vmware/FullBackupVMs"
> MOUNTPOINT=/mnt
> TMPDIR="/tmp/prebacula/$$.${RANDOM}"
>
> mkdir -p ${TMPDIR}
>
> # Sanity check: does a snapshot VM already exist? If so, something's
> # gone wrong in the past and we should just drop out now rather than
> exacerbate
> # the problem.
>
> if [ -e /dev/${VG}/${LV_SNAPSHOT} ]
> then
> echo "Snapshot already exists; failing"
> exit 1
> fi
>
>
> # pause VMs we want backed up.
> # essentially, any VM which is running and lives in $FULLBACKUPLOCATION.
>
> # sleep for 20 seconds between each VM pause because telling VMWare to pause
> # too many VMs at once seems to upset it.
>
> # List all VM's in $FULLBACKUPLOCATION
>
> /usr/bin/vmware-cmd -l | \
> grep ^${FULLBACKUPLOCATION} > ${TMPDIR}/vmlist
>
> # Find out state of each VM in $FULLBACKUPLOCATION, line number the result.
>
> cat ${TMPDIR}/vmlist | \
> xargs -d'\n' -I"{}" vmware-cmd "{}" getstate | \
> awk '{print $3}' | \
> nl -s" " -w3 > ${TMPDIR}/vmstates
>
> # Line number the list of VM's
>
> nl -s" " -w3 ${TMPDIR}/vmlist > ${TMPDIR}/vmlist-numbered
>
> # Join them, resulting in a list of VMs and their state.
>
> join ${TMPDIR}/vmstates ${TMPDIR}/vmlist-numbered >
> ${TMPDIR}/joined-vm-states
>
> # Grep for the VMs which are running, turn the list into something usable.
>
> grep "^.* on .*" ${TMPDIR}/joined-vm-states | \
> sed "s/^.* on //g" > ${TMPDIR}/working-list-VMs
>
> # Create the scripts which will pause and restart each VM, based on the
> # list of VMs which we want to stay on.
>
> sed "s/^/vmware-cmd \"/g
> s/$/\" suspend hard ; sleep 20 ; sync/g" ${TMPDIR}/working-list-VMs >
> ${TMPDIR}/
> suspend-VMs
>
> sed "s/^/vmware-cmd \"/g
> s/$/\" start ; sleep 20/g" ${TMPDIR}/working-list-VMs >
> ${TMPDIR}/restart-VMs
>
> . ${TMPDIR}/suspend-VMs
>
> # snapshot /home
> lvcreate -s -L6G -n ${LV_SNAPSHOT} /dev/${VG}/${LV}
>
> if [ $? ]
> then
> RETVAL=0
> mount /dev/${VG}/${LV_SNAPSHOT} ${MOUNTPOINT} -o ro
> if (! [ $? ] )
> then
> RETVAL=1
> echo "Couldn't mount snapshot /dev/${VG}/${LV_SNAPSHOT}"
> fi
> else
> RETVAL=1
> echo "Couldn't create snapshot of /dev/${VG}/${LV}"
> fi
>
> # Regardless of how well that went, we'd better restart the VM.
>
> . ${TMPDIR}/restart-VMs
>
> # This is rather safer than an rm -rf of our temp dir
>
> if [[ "${TMPDIR}" =~ "^/tmp*" ]]
> then
> find ${TMPDIR} -type f -maxdepth 1 | xargs rm
> rmdir ${TMPDIR}
> else
> echo "TMPDIR isn't in /tmp - leaving well alone"
> fi
>
> exit ${RETVAL}
>
>
>
>
>
-------------------------------------------------------------------------
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
|
|
|