VMware虚拟机无法从命令行恢复

时间:2011-02-23 17:31:20

标签: linux bash vmware ubuntu-10.10

我在Ubuntu 10.10上运行VMWare Workstation。我有一系列虚拟机,我每周都会克隆一次。

我编写了一个bash脚本,循环遍历每个虚拟机,轻轻地挂起它,克隆它,然后尝试恢复它。

问题是,VM没有恢复,所以我必须手动恢复它们。我试图找出如何修改我编写的脚本以确保VM恢复。我已经包含了脚本和生成的日志文件的示例,显示了错误消息。

#!/bin/bash

##Author:   William Cooper
##Date: 2/15/2011
## Purpose:     Perform full backups of Virtual Machines
##      Running under VMWare Workstation

## Script won't run if the /nas directory doesn't exist
## The /nas directory is a mounted Buffalo Terastation
## Check /etc/fstab if this mountpoint is broken
   BACKUPDEST="/nas"

## No need to modify
   HOST=`hostname`
   DATEFILE=`/bin/date +%G%m%d`

## Run Command to find list of VM names:
## this will only be the name of the vm, no path and no .vmx
   VMLIST=`vmrun list | grep '/' | cut -d'/' -f3 | cut -d'.' -f1`

## Initialize Counter variable used to cycle through VMs in VMARRAY variable
   COUNTER=1

## Run Command to find list of VM Names and then store them in an Array:
## This will include full pathnames
   VMARRAY=( `vmrun list | grep '/'` )

#################################################################
## Functions

##
## Notify the starting time of backup in the log
##
function startScript {
   echo
   echo "----------------------------------------------------"
   echo "START - ${VM}"
   echo "Host: ${HOST}"
   echo "Date: `date`"
   echo
}

##
## Suspend VM
##
function suspendVM {
   ## Suspend the VM
   echo "Attempting to softly suspend "${VM}" . . ."
   vmrun suspend ${VMARRAY[${COUNTER}]} soft
   echo "${VM} Suspended on `date`"
   echo
}

##
## Backup VM
##
function doBackup {

   ## Check to see if the correct backup directory exists.
   if [ ! -d ${BACKUPDEST}/${VM} ]; then
      echo "${BACKUPDEST}/${VM} does not exist, creating . . ."
      mkdir "${BACKUPDEST}/${VM}"
      echo
   fi

   ## Backup VM (clone)
   echo "Backup of "${VM}" began: `date`"
   echo "Backup to ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE} . . ."
   mkdir ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE}
   vmrun clone ${VMARRAY[${COUNTER}]} ${BACKUPDEST}/${VM}/BACKUP/${DATEFILE}/${VM}.vmx full
   echo "Backup of "${VM}" ended: `date`"
   echo
}

##
## Start VM
##
function doStart {
   ## Resume VMs which were running [--type gui|sdl|vrdp|headless]
   echo "Attempting to resume "${VM}" . . ."
   vmrun start ${VMARRAY[${COUNTER}]}
   echo "${VM} Resumed on `date`"
   echo
}

##
## Notify the finishing time of backup in the log
##
function finishScript {
   echo "FINISH - ${VM}"
   echo "Host: ${HOST}"
   echo "Date: `date`"
   echo "----------------------------------------------------"
   echo
}

#################################################################
## Script

for VM in ${VMLIST}
do

   sleep 1
   ## StartScrip executes for logging
      startScript

   ## Suspend VM performs soft suspend
      suspendVM
      sleep 3

   ## Do Backup performs the VM clone
      doBackup
      sleep 3

   ## Start VM performs start vm
      doStart
      sleep 3

   ## FinishScript executes for logging
      finishScript

   ## Increment the Counter
      COUNTER=${COUNTER}+1

done | tee "${BACKUPDEST}/logs/VMClone_${DATEFILE}.log"

## Script
#################################################################
exit

每个VM的生成日志文件示例如下所示。

----------------------------------------------------
START - vmname
Host: servername
Date: Sat Feb 19 12:30:29 CST 2011

Attempting to softly suspend vmname . . .
vmname Suspended on Sat Feb 19 12:30:44 CST 2011

Backup of vmname began: Sat Feb 19 12:30:47 CST 2011
Backup to /nas/vmname/BACKUP/20110219 . . .
Backup of vmname ended: Sat Feb 19 12:43:16 CST 2011

Attempting to resume vmname . . .
Error: Cannot launch the UI because no display server is present in the current environment
vmname Resumed on Sat Feb 19 12:43:20 CST 2011

FINISH - vmname
Host: servername
Date: Sat Feb 19 12:43:23 CST 2011
----------------------------------------------------

错误:无法启动UI,因为当前环境中没有显示服务器

4 个答案:

答案 0 :(得分:11)

您可以将nogui参数用于start命令,例如:

vmrun start yourmachine.vmx nogui

请参阅:http://www.vmware.com/pdf/vix180_vmrun_command.pdf

答案 1 :(得分:0)

由于没有找到可靠的答案,我只是接受在这些特定情况下无法解决的问题。

  • Ubuntu 10.10 x64
  • VMware Workstation 7

解决方案:关闭VMware Workstation并选择虚拟机“在后台运行” 在那之后完美无瑕地工作。

答案 2 :(得分:0)

尝试在运行vmware工作站的终端TTY上执行echo $ DISPLAY。 echo $ DISPLAY将返回如下:1000.0 你需要设置 在脚本中导出DISPLAY =“:1000.0”。然后脚本将恢复VM的.. 当我使用槟榔备份来恢复使用在槟榔中运行的postscript恢复我的VM时,我发现这是有效的。

答案 3 :(得分:0)

如果问题是因为您从ssh会话运行vmrun,则另一个解决方案可能是在服务器上运行屏幕会话。

机器上的

正在运行:

screen -S vmware

在客户端计算机上,

ssh vmware-machine
screen -x vmware
vmrun start /path/to/vm.vmx