[转]VMware ESX 3.0 VM Backup script by Tooms

news/2024/7/19 7:06:08 标签: vmware, command, server, delete, build, windows

转自http://ktcheong.spaces.live.com/blog/cns!72B9F5204F2D5FF2!312.entry

VMware ESX 3.0 VM Backup script by Tooms

I was looking around the internet for a backup script to backup the VM guests on a standalone ESX 3.0 and was not finding any so I start to make my own.

Things I need the script to-do was.

 

  • HOT Backup of all VM guest on the server
  • Backup of VM guests in any power state
  • Backup to a local folder on the server where the remote backup server will pick them from and put it to tapes
  • Auto cleanup of old backup log and VM files (older then 1 day)
  • Execute one script if there was a error and another if there was no error
  • No SAN, work on a standalone ESX server with local storage

and yes I know esxRanger 2.0 for ESX 3.0 can do all this, but that product was not finish and public when I start to make this script, maybe I will change to esxRanger but that will time tell or maybe I will use them both


Please be nice as this is my first Linux bash script and I am just a windows admin ;-) so there is for sure a number of error and smarter ways to do thing, but it works for me.. and if you give me feedback I will fix the script.



Here is the script and how to use it

1. login
login as root on the ESX 3.0 console


2. edit backuptools.conf
First edit the /etc/vmware/backuptools.conf file by running the command "nano /etc/vmware/backuptools.conf"
This is need in order for the vmware backup tools to work...
Out comment the red lines and put in the blue lines


#
# URL for the VC SDK instance to connect to. The format is
# [:port]
#
# VCHOST=myvirtualcenter.company.com
VCHOST=localhost

#
# Username to use for VC SDK authentication
#
# USERNAME=backup
USERNAME=root

#
# Password to user for VC SDK authentication
# WARNING: It is recommended that you don't specify the
# password in the configuration file.
#
# PASSWORD=XXX
PASSWORD=YourPassword

 

note the best thing will be to make a account for backup and not use the root account.

 

3. make a folder for the backup script
make a folder with the command "mkdir /etc/esxbackup"


4. backup script
make the script by using the command "nano
/etc/esxbackup/backup.bash" and copy the script below into it.
change the $TOfolder to be where you like the backup to be put.

###########################################################################
#!/bin/bash
#
# ESX 3.0 Backup script build by Tooms@tooms.dk
#
# 20060905 Minor fixs by tooms
# 20060830 First version by tooms
#
# Change the $TOfolder to be the folder where the backup files will be placed in
#
#


###########################################################################
# Path the vmware apps need.
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"


###########################################################################
# the base Path where the backup will be placed
# Change this path to match your setup
TOfolder=/vmfs/volumes/storage1/backup


############################################################################
# make the sub folder name ready from date/time
DTfolder=$(date '+%Y%m%d-%H%M')


############################################################################
# making the base folders ready if not exist
if test ! -x "$TOfolder" ; then
  mkdir -p $TOfolder
fi


############################################################################
# make a log file ready
rm -f $TOfolder/backup.log
Backuplog=$TOfolder/backup.log
echo " " >>$Backuplog
echo "The Date/time is $(date '+%Y%m%d-%H%M%S')" >>$Backuplog
echo " " >>$Backuplog


############################################################################
# making the sub-folders ready if there not exist
if test ! -x "$TOfolder/$DTfolder" ; then
  echo "Make folder: $TOfolder/$DTfolder" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder
fi
if test ! -x "$TOfolder/$DTfolder/vm" ; then
  echo "Make folder: $TOfolder/$DTfolder/vm" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder/vm
fi
if test ! -x "$TOfolder/$DTfolder/log" ; then
  echo "Make folder: $TOfolder/$DTfolder/log" >>$Backuplog
  mkdir -p $TOfolder/$DTfolder/log
fi


############################################################################
# move backup log to the new subfolder
mv $TOfolder/backup.log $TOfolder/$DTfolder/log/
Backuplog=$TOfolder/$DTfolder/log/backup.log
echo " " >>$Backuplog
echo "Move backup log to $Backuplog" >>$Backuplog


############################################################################
# build content log of $TOfolder before backup and cleanup
echo " " >>$Backuplog
echo "Build content_before.log of $TOfolder before backup and cleanup" >>$Backuplog
ls -R -la $TOfolder >>$TOfolder/$DTfolder/log/content_before.log


############################################################################
# Delete content from the $TOfolder there is older then 1 day
echo " " >>$Backuplog
echo "Delete content from the $TOfolder there is older then 1 day" >>$Backuplog
find $TOfolder/* -type d -maxdepth 0 -mtime +1 -exec rm -d -r -f -v {} >>$Backuplog /;


############################################################################
# Delete old vcbSnapAll logfiles from /var/log/vmware/ there is older then 1 day
echo " " >>$Backuplog
echo "Delete old vcbSnapAll logfiles from /var/log/vmware/ there is older then 5 min." >>$Backuplog
find /var/log/vmware/vcbSnapAll-* -type d -maxdepth 0 -mtime +1 -exec rm -d -r -f -v {} >>$Backuplog /;


############################################################################
# make the VM export/backup
echo " " >>$Backuplog
echo "Laver export af alle VM" >>$Backuplog
vcbSnapAll -a any -r $TOfolder/$DTfolder/vm/ -L 6 >>$Backuplog


############################################################################
# Getting the exitcode from vcbSnapAll
vcbSnapAll_exitcode=$(expr $?)
echo " " >>$Backuplog
echo "The exitcode is $vcbSnapAll_exitcode" >>$Backuplog


############################################################################
# copy the vcbSnapAll logfiles to the logfolder
echo " " >>$Backuplog
echo "copy the vcbSnapAll logfiles to $TOfolder/$DTfolder/log/" >>$Backuplog
cp -r -v /var/log/vmware/vcbSnapAll-* $TOfolder/$DTfolder/log/ >>$Backuplog


############################################################################
# build content log of $TOfolder after backup and cleanup
echo " " >>$Backuplog
echo "Build content_after.log of $TOfolder after backup and cleanup" >>$Backuplog
ls -R -la $TOfolder >>$TOfolder/$DTfolder/log/content_after.log


############################################################################
# write end time in logfile
echo " " >>$Backuplog
echo "The Date/time is $(date '+%Y%m%d-%H%M%S')" >>$Backuplog


############################################################################
# Checking for errors
echo " " >>$Backuplog
if [ $vcbSnapAll_exitcode = 0 ]; then
  echo "Error: none" >>$Backuplog
  echo " " >>$Backuplog
  #run script if all okey !
else
  echo "Error: got exitcode $vcbSnapAll_exitcode" >>$Backuplog
  echo " " >>$Backuplog
  #run script if there is a error !
fi



5. Make it a script
run this command "chmod 777 /etc/esxbackup/backup.bash" to make it a script there can be run from the commandline


6. When to run the backup
edit the crontap fil with the command "nano /etc/crontap" to run the script at 21:00 every evening
Add the line mark with blue

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 21 * * * root /etc/esxbackup/backup.bash
 


7. Try the script
Try the script by running the command "/etc/esxbackup/backup.bash"


8. Look at the backup log
Look at the backup log with the command "nano /vmfs/volumes/storage1/backup/20060905-1800/log/backup.log"
note that the path will offcource not be the same when you use it...


9. Backup to tape
Now setup your remote backup server to backup any thing in the /vmfs/volumes/storage1/backup folder, I use Backup Exec 10D on a windows server with the backup exec 9.1 linux agent installed in the ESX 3.0 server COS.
That works very well with backup speed at around 1500mb/min over a 1gbit network with a LTO3 24 tape autoloader from Dell on the windows server.



And yes before you ask how to restore a VM from the backup folder......
First turn off the VM there need to be restore and do like this

[root@ESX3 root]# vcbRestore -s /vmfs/volumes/storage1/backup/20060905-1800/vm/vm01/ -b overwrite
[2006-09-06 18:30:00.140 'App' 3076448384 info] Current working directory: /root
[2006-09-06 18:30:00.157 'BaseLibs' 11344816 warning] [Vmdb_Unset] Unsetting unknown path: /vmomi/

Converting "/vmfs/volumes/storage2//VM_vm01/vm01.vmdk" (VMFS (flat)):
0%=====================50%=====================100%
**************************************************

[root@ESX3 root]#
 

 

 

Now turn on the VM that is just restore and verify it is working.


hope this help you on the way and works on your box, let me know in the forum if you have any smart things there need to be add to the backup script and I will then update it from time to time...


not bad from a windows admin with only a very little linux skills ;-)

 

 


http://www.niftyadmin.cn/n/1055256.html

相关文章

wifi-帧分片

802.11支持帧分片,可以将一个数据帧分为多个分片。使用帧分片时,每个分片有自己的MAC头和尾部CRC,各分片可以独立处理。当信道有明显干扰时,分片有助于提高到达率,从而提交性能。 由于分片只传输整个帧的一部分数据&a…

java实现自动化发布平台核心代码

1.搭建jenkins环境 (1)jenkins官网下载jenkins.war包 (2)将该war包放入到tomcat的webapp的目录下(前提条件需要配置tomcat的环境,详情请自行百度) (3)启动tomcat(在tomcat的bin目录下执行"./start.sh")脚本,等待tomcat启动成功 (4)访问jenkins地址如:http://ip:端口/…

Unity 中的脚本的方法的执行顺序和几种Update的区别

在Uinty中创建脚本系统会自带几个方法,这是系统调用脚本的顺序,有些的人叫它为脚本的生命周期: Awake --> Start --> Update --> FixedUpdate --> LateUpdate -->OnGUI -->Reset --> OnDisable -->OnDestroy 当然这些…

Mongodb高级查询Aggregation聚合组件分页

用Mongo的聚合组件Aggregation要用到两个方法skip和limit。skip设置起点(分页的时候不包含起点,从起点的下一行开始),limit设置条数。如: Aggregation.skip(10), Aggregation.limit(20)的意思是(10,20)第…

关于加解密

应用程序中的签名验签与链路层的CRC一脉相承,都是对数据进行校验,防止数据被篡改,丢弃接收到的不完整数据。

[转]VCB (VMware Consolidated Backup)的应用

转自 VCB下载安装很容易,只是装完没有任何体现在程序组里,容易让初学者怀疑自己是否安装正确。VCB的使用都是在DOS命令行使用格式:vcbmounter -h "HOSTIP" -u "username" -p "passowrd" -a ipaddr:"VMIP&…

一个IT民工的十一日记(四)

2009年的10月3日 星期六 天气晴民工依旧六点起床,爹娘依旧七点去上班,而民工也依旧在爹娘出发后,一个人去地里掰棒子。今天是八月十五了,传说中的中秋节!当大多数的北漂在游山玩水庆祝中秋的时候,民工一个人…

前端总结挺全面的

前端UI框架组件库: 说到前端框架我第一印象中想起React、Vue和Angular,不知道你是否与我一样想到这些,现在常用的有:Bootstrap、jQuery UI、BootMetro、AUI常用的还有很多、就不一一跟大家举例出来了,因为很多朋友认为…