vmware_backup.sh
by
scott_glaser
—
last modified
Jan 30, 2007 10:47 AM
This script stops the vmware image, makes a tarball copy and moves it to a pre-determined directory.
vmware_backup.sh
—
text/x-sh,
1Kb
File contents
#!/bin/bash
# Project: Vmware Backup Script
# Date Started: 2006-11-03
#
#
ROOT_UID=0 # Only users with $UID 0 have root privileges.
VM_DIR=/disk2/Virtural_Machines/ # Path to virtural machines, this will vary based on you installation.
VM_IMAGE=mail01.theglaserfamily.org # Name/Directory of the virtural machine image
BU_PATH=/disk2/backups # Path to the backup directory
E_NOTROOT=67 # Non-root exit error.
# Future plan is to automatically generate a list of all images in the $VM_DIR so that the script can be fully
# automated to determin all the images that need to be backed up.
# 1. Check the state of the virtural machine.
# needs one parameter (dir of image to back up)
function backup_image()
{
echo "Getting the state of $1"
STATE=$(vmware-cmd ${VM_DIR}${1}/${1}.vmx getstate)
echo "Testing the state of $1"
if [ "$STATE" = "getstate() = on" ]
then
echo "Shutting down $1"
MESSAGE=$(vmware-cmd ${VM_DIR}${1}/${1}.vmx stop)
if [ "$MESSAGE" != "stop() = 1" ]
then
echo "$1 could not be stopped"
return 1
fi
else
echo "$1 won't be backed up; it is not running"
return 1
fi
echo "Starting backup of $1"
# tar cvzf $BU_PATH/$VM_IMAGE-`date +%s`.tar.gz $1/*
echo "here, we would create a tarball of $1"
echo "Backup complete, restarting $1"
vmware-cmd ${VM_DIR}${1}/${1}.vmx start
}
cd $VM_DIR
for dir in *
do
echo "here we would backup $dir"
#backup $dir
done

