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

发布于 2024-10-18 21:28:00 字数 3977 浏览 5 评论 0原文

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

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

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

#!/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

下面显示了为每个虚拟机生成的日志文件的示例。

----------------------------------------------------
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,因为当前环境中不存在显示服务器

I'm running VMWare Workstation on Ubuntu 10.10. I have a series of virtual machines that I clone every week.

I've written a bash script that cycles through each of the virtual machines, softly suspends it, clones it, and then attempts to resume it.

The problem is, the VM's do not resume, so I have to manually resume them. I'm trying to figure out how I can modify the script I've written to ensure the VMs resume. I've included the script and a sample of the generated logfile showing the error message.

#!/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

An example of the generated logfile for each VM is shown below.

----------------------------------------------------
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
----------------------------------------------------

Error: Cannot launch the UI because no display server is present in the current environment

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇女薄笑 2024-10-25 21:28:00

您可以在启动命令中使用 nogui 参数,例如:

vmrun start yourmachine.vmx nogui

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

You could use the nogui paramater to the start command, e.g:

vmrun start yourmachine.vmx nogui

See: http://www.vmware.com/pdf/vix180_vmrun_command.pdf

掩于岁月 2024-10-25 21:28:00

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

  • Ubuntu 10.10 x64
  • VMware Workstation 7

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

Since no solid answer has been found I'm just going to accept that under these specific circumstances there is no fix.

  • Ubuntu 10.10 x64
  • VMware Workstation 7

Solution: Close down VMware Workstation and choose for the VMs to "Run in the Background"
Works flawlessly after that.

你如我软肋 2024-10-25 21:28:00

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

try doing echo $DISPLAY on your terminal TTY where vmware workstation runs.
The echo $DISPLAY will return like :1000.0
you need to set
export DISPLAY=":1000.0" in your script. then the script will resume the VM's..
i found this works when i use areca backup to resume my VM using postscript run in areca.

旧人哭 2024-10-25 21:28:00

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

在工作站正在运行的计算机上:

screen -S vmware

在客户端计算机上,

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

if the problem is because you are running vmrun from a ssh session, then another solution might be run a screen session on the server.

on the machine Workstation is running:

screen -S vmware

on the client machine,

ssh vmware-machine
screen -x vmware
vmrun start /path/to/vm.vmx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文