用户名:  密码:  验证码: 验证码  注册  找回
RSS
无双网
 2019年03月22日 星期五  您现在位于: 首页 → 技术文栏 → VMware ESX 3.0 V...

VMware ESX 3.0 VM Backup script by Tooms

2011年06月17日  无双网  出处:
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 ;-)

转自:/20101129233317169.entry
 (本文已被浏览 428 次)
 发布人:[标签:发布人]
 → 推荐给我的好友
上篇文章:变通式VMware Consolidate...
下篇文章:摘录一些解决VMware Snapshot...
发表评论
  → 评论内容 (点击查看)   共0条评论,每页显示5条评论   浏览所有评论
(没有相关评论)
  → 发表我的评论 (点击发表)
热门文章
 保存webbrowser中的HTML内...
 全部DLL下载
 用VB6.0设计简易赛车游戏
 游戏对照表
 MSFlexGrid使用技巧一例
 添加红月装备的详细教程 (包括装备 武...
 Win2003+Discuz!5.5+II...
 用vb6的ActiveX控件实现异步下...
 PC经典RPG《仙剑奇侠传Ⅰ》for PP...
 能否判断动态数组有没有被分配过
最新文章
 [ODBC SQL Server Driv...
 评论:115网盘的何去何从
 我科学家实现百公里量级自由空间量子隐形...
 中国智能手机出货量占全球27%居世界之...
 Gartner:2012 第二季度西欧 P...
 [多图]华山论剑:当今在世的智商最高的...
 三星获出租车服务系统专利 可快速查看驾...
 [多图]15项可能延续到2030年的科...
 分析称苹果三星专利大战输赢已成定论
 Google终获云操作系统专利
 网站留言· 友情链接·与我在线·网站地图联系我们·管理·TOP 
 陕ICP备09004157号  
 Copyright © 2012 Asp126.com Inc. All Rights Reserved.Processed in 0.016s, 8 queries, 36 Cache,0 Online