winlin
Goto Top

Probleme mit VM Backupskript

Hallo Leute,

ich habe ein VM Backupskript (*.sh) bekommen das noch einige libaries benötigt, sowie ich es interpretieren konnte...Bin kein shell-Programmierer und benötige dringend Hilfe von Profis. Anbei das Skript:

#! /bin/bash
 
##
## Change the information below
##
USER=root
PASS=PASSWORT
BACKUPDEST=/backup/vmware
DAYS_TO_KEEP_TAR=1
 
## include any VMs in this array that you do NOT want backed up.  Use
## the directory name.
EXEMPTION_ARRAY=( None )
 
## Do not modify anything below this line
HOST=$(hostname)
DATE=$(date)
VMCMD=vmware-vim-cmd
VM_WAS_RUNNING=false
VM_EXEMPT=false
 

##
## Create the backup directories if they do not exist
##
function doCheckDirectories
{
	## if the archives directory does not  exist, create it
	if [ ! -d $BACKUPDEST/archives ]; then
 
		echo "$BACKUPDEST/archives does not exist, creating."  
 
		mkdir $BACKUPDEST/archives
	fi
 
	## if the directories directory does not exist, create it
	if [ ! -d $BACKUPDEST/directories ]; then
 
		echo "$BACKUPDEST/directories does not exist, creating."  
		
		mkdir $BACKUPDEST/directories
 
	fi
}
 
##
## If this VM is in our exempt array, set VM_EXEMPT to skip entirely.
##
function doCheckExempt
{
	# iterate throught the array, if we get a match, set
	# VM_EXEMPT to true
	for check_vm in ${EXEMPTION_ARRAY[@]}; do
 
		if [ "$check_vm" = "$NAME" ]; then  
 
			echo "$NAME is on the exception list, skipping."  
 
			VM_EXEMPT=true
		fi
	done
}

##
## Get current state and location of current VM.
##
function setVM
{

	STATE=`$VMCMD -U $USER -P $PASS vmsvc/power.getstate $VMID |sed 1d`
        DATASTORE=`$VMCMD -U $USER -P $PASS vmsvc/get.datastores $VMID |tr -s ' '|sed '2!d;s/^[[:alnum:]]* //;s/ //g'`  
	VMDIR=${LOC%/*}

}

##
## suspend a VM if its running, skip it if not
##
function suspendVM
{
 
	echo $NAME state is currently: $STATE
 
	# if its running, suspend it, otherwise, move on.
	if [ "$STATE" = "Powered on" ]; then  
 
		echo "Suspending $NAME . . ."  

		$VMCMD -U $USER -P $PASS vmsvc/power.suspend $VMID

		if [ $? == 0 ]; then
		
			# track if it was running, so I can restart or not
			VM_WAS_RUNNING=true

			echo "$NAME Suspended - $(date)"  

			return

		else
			echo "$NAME DID NOT SUSPEND!! Exiting Program."  
			exit 0
		fi
	else
		echo "$NAME was not suspended, not suspending - $(date)"  
	fi
}
 
##
## backup the VM
##
function doBackup
{
 
	# synchronise (update) all data to the directories tree
	echo "Backing up (rsync) $NAME to $BACKUPDEST/directories/$VMDIR"  
	rsync -ax --numeric-ids --delete $DATASTORE/$VMDIR/ $BACKUPDEST/directories/$VMDIR/

}
 
##
## Resume the VM if we it was running in the first place
##
function resumeVM
{
	if [ "$VM_WAS_RUNNING" = "true" ]; then  
 
		# reset for next VM
		VM_WAS_RUNNING=false
 
		echo "Powering on $NAME . . ."  

		$VMCMD -U $USER -P $PASS vmsvc/power.on $VMID
		
                if [ $? == 0 ]; then
 
			echo "$NAME restarted - $(date)"  
		else
			echo "$NAME FAILED TO RESUME!! Exiting Program."  
			exit 0
		fi
 
	else
		echo "$NAME was not running, not resuming - $(date)"  
	fi
}
 
##
## tgz up the directory for a more compressed and mobile backup.
##
function doTar
{
 
	fileName=backup_$NAME-`/bin/date +%G%m%d`.tgz	
 	echo "taring up $NAME to $BACKUPDEST/archives/$fileName"  
	tar -cPpszf $BACKUPDEST/archives/$fileName $BACKUPDEST/directories/$VMDIR
 
}
 
##
## Clean up any tars that are older than DAYS_TO_KEEP_TAR
##
function doCleanTar
{

	echo "Cleaning up tars older than $DAYS_TO_KEEP_TAR"  
	find $BACKUPDEST/archives -name "backup_$NAME*.tgz" -mtime $DAYS_TO_KEEP_TAR -exec rm -vf {} \;  
	#find $BACKUPDEST/archives -mtime +1 -exec rm -vf {} \;

}
 
##
## Main Loop, iterate through the VMs and handle them apprpriately
##

echo "-----------------------------------------------------"  
echo "START"  
echo "Host: $HOST"  
echo "Date: $DATE"  
echo "-----------------------------------------------------"  
 
# make sure we have the appropriate directories for backups
doCheckDirectories

while read VMID NAME TYPE LOC OS VMVER; do
	echo "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"  
	
	setVM
	echo "Current VM is $DATASTORE/$LOC"  

	# check to see if current vm should be exempted
	doCheckExempt

	# only back up if it is not on the exempt list
	if [ "$VM_EXEMPT" = "false" ]; then  

		# suspend my VM if its running
		suspendVM
		sleep 30

		# actually do the directory backup
		doBackup
		sleep 5

		# resume the VM if it was running to begin with
		resumeVM
		sleep 5

		# tar it up
		doTar
		sleep 5

		# and finally, clean up my old tars
		doCleanTar
		sleep 5

	fi

		# reset for next vm
		VM_EXEMPT=false

done < <($VMCMD -U $USER -P $PASS vmsvc/getallvms |sed 1d)

echo "-----------------------------------------------------"  
echo "FINISH"  
echo "Host: $HOST"  
echo "Date: $(date)"  
echo "-----------------------------------------------------"  

Also bei mir gibt es den Befehl "vmrun" und den Befehl "vmware-vim-cmd". Wenn ich im Skript vmrun für VMCMD eingebe erhalten ich folgenden output:
-----------------------------------------------------
START
Host: hsot345
Date: Mon Jan 28 10:37:35 CET 2013
-----------------------------------------------------
-----------------------------------------------------
FINISH
Host: hsot345
Date: Mon Jan 28 10:37:35 CET 2013
-----------------------------------------------------

Wie man sieht ohne Fehler - aber ich sehe das hier kein Backup gemacht worden ist da Start und Finish in der selben Sekunde stattifindet.
Gebe ich aber nun vmware-vim-cmd ein erhalten ich das hier:
START
Host: hsot345
Date: Mon Jan 28 10:39:23 CET 2013
-----------------------------------------------------
/usr/lib/vmware/bin/vmware-vim-cmd: /usr/lib64/libxml2.so.2: no version information available (required by /usr/lib/vmware/lib/libvmwarebase.so.0/libvmwarebase.so.0)
/usr/lib/vmware/bin/vmware-vim-cmd: /usr/lib64/libxml2.so.2: no version information available (required by /usr/lib/vmware/lib/libvmwarebase.so.0/libvmwarebase.so.0)
/usr/lib/vmware/bin/vmware-vim-cmd: /usr/lib64/libxml2.so.2: no version information available (required by /usr/lib/vmware/lib/libvmwarebase.so.0/libvmwarebase.so.0)
Failed to login: Invalid response code: 404 Not Found
-----------------------------------------------------
FINISH
Host: hsot345
Date: Mon Jan 28 10:39:24 CET 2013

Was muss ich denn nun hier nachinstallieren damit mein Skript läuft??? Die libxml2.so.2

Content-Key: 197756

Url: https://administrator.de/contentid/197756

Printed on: April 19, 2024 at 21:04 o'clock

Mitglied: 110135
110135 Jan 28, 2013 at 09:50:49 (UTC)
Goto Top
Hallo,

um welche VMWare-Version handelt es sich? ESXi?

Gruß
Florian
Member: winlin
winlin Jan 28, 2013 at 09:55:18 (UTC)
Goto Top
ne es handelt sich um VMware Workstation v9
Mitglied: 110135
110135 Jan 28, 2013 at 09:57:12 (UTC)
Goto Top
Okay, da bin ich dann raus. Sorry.
Member: winlin
winlin Jan 28, 2013 updated at 10:02:46 (UTC)
Goto Top
bei einer anderen Maschine auf der Workstation v8 installiert ist erhalte ich da schon mehr...
-----------------------------------------------------
START
Host: hsot345
Date: Mon Jan 28 11:00:18 CET 2013
-----------------------------------------------------
Failed to login: vmodl.fault.SystemError
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Failed to login: vmodl.fault.SystemError
Failed to login: vmodl.fault.SystemError
Current VM is author:VMware,Inc./
VMware, state is currently: author: VMware, Inc. description: VMware Virtual Machine Monitor. license: GPL v2 supported: external vermagic: 2.6.18-8.el5 SMP mod_unload gcc-4.1 depends:
VMware, was not suspended, not suspending - Mon Jan 28 11:00:18 CET 2013
Backing up (rsync) VMware, to /backup/vmware/directories/
ssh: author: Name or service not known
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: unexplained error (code 255) at io.c(463) [receiver=2.6.8]
VMware, was not running, not resuming - Mon Jan 28 11:00:53 CET 2013
taring up VMware, to /backup/vmware/archives/backup_VMware,-20130128.tgz
Cleaning up tars older than 1
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Member: Rudbert
Rudbert Jan 28, 2013 at 11:19:38 (UTC)
Goto Top
Hallo,


wenn schon Bastelbackup, nimmm doch eins, für das du in den offiziellen Foren auch Support erhältst durch die Programmierer und das gut dokumentiert ist:

http://communities.vmware.com/docs/DOC-8760


mfg
Member: winlin
winlin Jan 28, 2013 at 11:32:45 (UTC)
Goto Top
ach super....ich denke das ist genau das richtige für mich face-smile
Mitglied: 110135
110135 Jan 28, 2013 at 13:48:54 (UTC)
Goto Top
Wenn ich mich kurz einschalten darf:

ghettoVCB ist schon gut, aber nicht für Workstation geeignet. Nutze es selber in meiner Testumgebung. Für Produktivumgebungen würde ich immer ein ordentliches Backupsystem nutzen!