免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2566 | 回复: 0
打印 上一主题 下一主题

发一个XENSERVER实用的bash给大家.绝对原创 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-13 05:01 |只看该作者 |倒序浏览
迅速清除VM的C盘.以模板系统的C盘代替..
其它盘不用动..
其效果..可想而知...
  1. #!/bin/sh
  2. #reset driver C
  3. #write by bendy 67052 [at] qq.com

  4. if [ -z "${XE}" ]; then
  5.   XE=xe
  6. fi

  7. # Check there's a vm uuid parameter to the command
  8. if [ $# -ne 1 ]; then
  9.         echo "usage: $0 <vm_uuid_to_reset>"
  10.         exit 1
  11. fi
  12. vmuuid=$1

  13. # Check if there's a VM by the uuid specified
  14. ${XE} vm-list params=uuid | grep -q " ${vmuuid}$"
  15. if [ $? -ne 0 ]; then
  16.         echo "error: no vm uuid \"${vmuuid}\" found"
  17.         exit 2
  18. fi

  19. # Check the power state of the vm
  20. name=$(${XE} vm-list uuid=${vmuuid} params=name-label --minimal)
  21. state=$(${XE} vm-list uuid=${vmuuid} params=power-state --minimal)
  22. wasrunning=0

  23. # If the VM state is running, we shutdown the vm first
  24. if [ "${state}" = "running" ]; then
  25.         ${XE} vm-shutdown uuid=${vmuuid}
  26.         ${XE} event-wait class=vm power-state=halted uuid=${vmuuid}
  27.         wasrunning=1
  28. fi

  29. # destroy OLD C
  30. ${XE} vbd-destroy uuid=`${XE} vbd-list vm-uuid=${vmuuid} device=hda | /usr/bin/perl -e 'while (<STDIN>) { if (/^uuid.* ([^ ]*)$/) { $uuid = $1; } } print "$uuid";'`
  31. #echo "destroy ok"

  32. # get drivce c uuid
  33. viduuid=$(${XE} vbd-list device=hda  | /usr/bin/perl -e 'while (<STDIN>) { if (/vdi-uuid.* ([^ ]*)$/) { $uuid = $1; } if ( $find ) { last;} if (/vm-name-label \( RO\): win/) { $find="yes" } } print "$uuid";')
  34. #echo ${viduuid}

  35. # clone driver C
  36. newviduuid=$(${XE} vdi-clone new-name-label=clone uuid=${viduuid})
  37. #echo "${newviduuid}"

  38. # inst new vbd
  39. ${XE} vbd-create vm-uuid=${vmuuid} device=hda vdi-uuid=${newviduuid} bootable=true type=Disk mode=RW
复制代码


(tips...模板系统的LABEL需要是win开头)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP