ghettoVCB.sh 介绍
ghettoVCB.sh 此脚本主要是针对VMWare ESXi 备份、还原使用。目前能使用的版本有ESX(i)3.5/4.x/5.x,使用的方法类似VMware的VCB的工具执行备份。ghettoVCB.sh的工作流程大致为,执行虚拟机的快照,然后进行备份,当备份完成后会删除快照。而此脚本最大的特色为可在虚拟机在线时备份,而不用停机备份。
本文准载自:http://blog.faq-book.com/?p=6158
ghettoVCB.sh 设定
一、准备工作
开启VMWare ESXi SSH
1. 开启SSH
[Configuration] → [Security Profile] → [Properties]
2. [SSH] → [Options] → [Start]
放置ghettoVCB文件
在放置ghettoVCB文件可分为两种方式,选一种来用就行了。
方式一 :
上传文件
1.下载ghettoVCB
2. 上传lamw-ghettoVCB-518cef7.tar.gz
把刚刚下载好的lamw-ghettoVCB-518cef7.tar.gz上传到ESXi Server。
使用VMware vSphere Client上传
[Configuration] → [Storage] → [datastore1] → [Browse Datastore]
3.选择档案要存放的路径,然后点,选Upload File
4. 上传完成后,会看到刚上传好的lamw-ghettoVCB-518cef7.tar.gz,如果没出线的话可按一下
方式二 :
下载档案
1. 使用SSH 登入ESXi Server
2. 下载档案
1
2
3
4
5
|
~ # cd /vmfs/volumes/datastore1
~ # wget http://download.faq-book.com/download/System/VMware/ghettoVCB
/ lamw - ghettoVCB - 518cef7.tar.gz
Connecting to download . faq - book . com ( 61.66.28.156 : 80 )
lamw - ghettoVCB - 518ce 100 % | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 15425 0 : 00 : 00 ETA
|
3. 查看档案
查看档案会看到已下载完成的lamw-ghettoVCB-518cef7.tar.gz
1
2
3
|
~# ls
ISO VM1 VM2
VM3 lamw-ghettoVCB-518cef7.tar.gz
|
二、ghettoVCB.sh安装与设定
在开始安装之前有一点要注意一下
由于ESXi重开机之后会把某些资料删除,因此会建议把此文件留在datastore1此硬盘空间内,才不会因重开机后文件就被删除了。
[ Note]
因5.1版为最新版本,而 ghettoVCB 尚未更新至最新板。如果是使用VMware ESXi 5.1版的,在 ghettoVCB.sh 以下有个地方要修改。要不然在使用上会出现版本序号有问题。
[Note]
若是下载 ghettoVCB-master版本的无需修改以下配置
大约在第231行会看到以下程式码,请加入|| [[ "${ESX_VERSION}" == "5.1.0" ]]。多加上5.1版本的判断。
这边有修改好的ghettoVCB.sh
1
2
3
4
5
6
7
8
9
10
|
~ # vi ghettoVCB.sh
# 修改前
230 ESX_VERSION = $ ( vmware - v | awk '{print $3}' )
231 if [ [ "${ESX_VERSION}" == "5.0.0" ] ] ; then
232 VER = 5
# 修改后
230 ESX_VERSION = $ ( vmware - v | awk '{print $3}' )
231 if [ [ "${ESX_VERSION}" == "5.0.0" ] ] || [ [ "${ESX_VERSION}" == "5.1.0" ] ] ; then
232 VER = 5
|
修改前
修改后
1. 安装
基本上datastore1的路径为/vmfs/volumes/datastore1
解tar后会看到ghettoVCB.sh,此脚本正是所需要的
1
2
3
4
5
6
7
|
~# cd /vmfs/volumes/datastore1
~# tar -zxvf lamw-ghettoVCB-518cef7.tar.gz
~# cd lamw-ghettoVCB-518cef7
~# ls
README ghettoVCB-restore.sh
ghettoVCB-vm_backup_configuration_template ghettoVCB.conf
ghettoVCB-restore_vm_restore_configuration_template ghettoVCB.sh
|
2. 相关设定档参数说明
2.1 ghettoVCB.sh 设定档
说明ghettoVCB.sh 设定档内常用的设定
这边有修改好的ghettoVCB.sh设定档,提供下载参考
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
~ # vi ghettoVCB.sh
# Author: William Lam
# Created Date: 11/17/2008
# http://www.virtuallyghetto.com/
# http://communities.vmware.com/docs/DOC-8760
################################################## ################
# directory that all VM backups should go (eg /vmfs/volumes/SAN_LUN1/mybackupdir)
# 设定备份后的储存位置,可自行修改储存位置。
VM_BACKUP_VOLUME = / vmfs / volumes / dlgCore - NFS - bigboi . VM - Backups / WILLIAM_BACKUPS
# Format output of VMDK backup
# zeroedthick
# 2gbsparse
# thin
# eagerzeroedthick
# 定义备份的硬碟格式,想了解硬碟格式说明请参考「VMware vSphere(ESXi) 虚拟硬碟格式介绍」
DISK_BACKUP_FORMAT = thin
# Number of backups for a given VM before deleting
# 定义备份保留的数量
VM_BACKUP_ROTATION_COUNT = 3
# Shutdown guestOS prior to running backups and power them back on afterwards
# This feature assumes VMware Tools are installed, else they will not power down and loop forever
# 1=on, 0 =off
# 虚拟机POWER OFF时不会要求snapshotting (enable=1,disable=0)
POWER_VM_DOWN_BEFORE_BACKUP = 0
# enable shutdown code 1=on, 0 = off
# 定义没有安装VMware Tools的虚拟机是否可以在硬碟POWER OFF时启用"POWER_VM_DOWN_BEFORE_BACKUP"
ENABLE_HARD_POWER_OFF = 0
# if the above flag "ENABLE_HARD_POWER_OFF "is set to 1, then will look at this flag which is the # of iterations
# the script will wait before executing a hard power off, this will be a multiple of 60seconds
# (eg) = 3, which means this will wait up to 180seconds (3min) before it just powers off the VM
# 如果启用"ENABLE_HARD_POWER_OFF"此定义执行强制关闭时会倒数运算,单位3为3分钟180秒
ITER_TO_WAIT_SHUTDOWN = 3
# Number of iterations the script will wait before giving up on powering down the VM and ignoring it for backup
# this will be a multiple of 60 (eg) = 5, which means this will wait up to 300secs (5min) before it gives up
# 设定POWER DOWN的时间。等待关闭时VM会放弃或忽略特定的VM备份。单位5为5分钟300秒
POWER_DOWN_TIMEOUT = 5
# enable compression with gzip+tar 1=on, 0=off
# 备份是否启用压缩(enable=1,disable=0)
ENABLE_COMPRESSION = 0
############################
####### NEW PARAMS #########
############################
# Include VMs memory when taking snapshot
# 是否启用VM 虚拟机的快照记忆体(enable=1,disable=0)
VM_SNAPSHOT_MEMORY = 0
# Quiesce VM when taking snapshot (requires VMware Tools to be installed)
# 是否启用对停止的VM 虚拟机使用快照(需有安装VMware Tools)
VM_SNAPSHOT_QUIESCE = 0
################################################## ########
# NON-PERSISTENT NFS-BACKUP ONLY
#
# ENABLE NON PERSISTENT NFS BACKUP 1=on, 0=off
# 接下来为NFS的相关设定
# 以下是给不想让NFS与系统长期连接的设定。允许只在备份的过程中连接到NFS,
并使用到以下6个变数。
#定义非持久性的NFS备份
ENABLE_NON_PERSISTENT_NFS = 0
# umount NFS datastore after backup is complete 1=yes, 0=no
# 是否要卸载NFS(yes=1,no=0)
UNMOUNT_NFS = 0
# IP Address of NFS Server
# NFS Server 的地址(ip或主机名)
NFS_SERVER = 172.51.0.192
# Path of exported folder residing on NFS Server (eg /some/mount/point )
# NFS 存放档案的路径
NFS_MOUNT = / upload
# Non-persistent NFS datastore display name of choice
# NFS 资料存放地方的名称
NFS_LOCAL_NAME = backup
# Name of backup directory for VMs residing on the NFS volume
# 虚拟机上NFS备份的目录
NFS_VM_BACKUP_DIR = mybackups
############################
######### EMAIL ############
############################
# 以下是MAIL 发送LOG的设定
# Email debug 1=yes, 0=no
# 是否发送debug的LOG,这是做为测试使用
EMAIL_DEBUG = 0
# Email log 1=yes, 0=no
# 是否要透过电子邮件来发送备份LOG (yes=1,no=0)
EMAIL_LOG = 0
# Email Delay Interval from NC (netcat) - default 1
# 设定每封mail之间发送的延迟时间。
EMAIL_DELAY_INTERVAL = 1
# Email SMTP server
# Email 的SMTP server的ip或网址
EMAIL_SERVER = auroa . primp - industries . com
# Email SMTP server port
# 设定mail 所使用的port
EMAIL_SERVER_PORT = 25
# Email FROM
# 寄件人的mail
EMAIL_FROM = root @ ghettoVCB
# Email RCPT
# 收件人的mail
EMAIL_TO = auroa @ primp - industries . com
########################## DO NOT MODIFY PAST THIS LINE ################## ########
# RSYNC LINK 1=yes, 0 = no
RSYNC_LINK = 0
LOG_LEVEL = "info"
VMDK_FILES_TO_BACKUP = "all"
# default 15min timeout
# 设定等待VM快照的时间,在等待关闭时会放弃和忽略特定备份的VM
SNAPSHOT_TIMEOUT = 15
LAST_MODIFIED_DATE = 2011_11_19
VERSION = 1
VERSION_STRING = $ { LAST_MODIFIED_DATE } _ $ { VERSION }
# Directory naming convention for backup rotations (please ensure there are no spaces!)
VM_BACKUP_DIR_NAMING_CONVENTION = "$(date +%F_%H-%M-%S)"
|
2.2 ghettoVCB.sh 参数使用说明
以下是ghettoVCB.sh相关参数的使用说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
~# ./ghettoVCB.sh
Loggingoutputto"/tmp/ghettoVCB-2012-10-16_15-46-10.log"...
2012-10-1615:46:10--info:ERROR:Incorrectnumberofarguments!
################################################## #############################
#
# ghettoVCB for ESX/ESXi 3.5, 4.x+ and 5.0
# Author: William Lam
# http://www.virtuallyghetto.com/
# Documentation: http://communities.vmware.com/docs/DOC-8760
# Created: 11/17/2008
# Last modified: 2011_11_19 Version 1
#
################################################## #############################
Usage:./ghettoVCB.sh-f[VM_BACKUP_UP_LIST]-c[VM_CONFIG_DIR]-l[LOG_FILE]-d[DEBUG_LEVEL]-g[GLOBAL_CONF]-e[VM_EXCLUSION_LIST]
OPTIONS:
-a BackupallVMsonhost
(备份主机上所有的虚拟机)
-f ListofVMstobackup
(针对List名单内的虚拟机备份)
-c VMconfigurationdirectoryforVMbackups
(VM配置目录forVM备份)
-g PathtoglobalghettoVCBconfigurationfile
-l Filetooutputlogging
(将LOG记录写到指定档案内)
-d Debuglevel[info|debug|dryrun](default:info)
(Debug测试,不会产生备份)
(e.g.)
BackupVMsstoredinalist
只备份list内的虚拟机
./ghettoVCB.sh-fvms_to_backup
BackupallVMsresidingonthishost
全部备份
./ghettoVCB.sh-a
BackupallVMsresidingonthishostexceptfortheVMsintheexclusionlist
除了 排除清单(vm_exclusion_list)上的虚拟机外,剩下的都备份
./ghettoVCB.sh-a-evm_exclusion_list
BackupVMsbasedonspecificconfigurationlocatedindirectory
根据vm_backup_configs中特定配置来备份vms_to_backup内指定的虚拟机
./ghettoVCB.sh-fvms_to_backup-cvm_backup_configs
BackupVMsusingglobalghettoVCBconfigurationfile
备份虚拟机时使用ghettoVCB.conf此设定档来备份vms_to_backup内指定的虚拟机
./ghettoVCB.sh-fvms_to_backup-g/global/ghettoVCB.conf
Outputwilllogto/tmp/ghettoVCB.log(considerloggingtolocalorremotedatastoretopersistlogs)
输出的记录到/tmp/ghettoVCB.log(可自行设定LOG所储存的路径和档案)
./ghettoVCB.sh-fvms_to_backup-l/vmfs/volume/local-storage/ghettoVCB.log
Dryrun(nobackupwilltakeplace)
Debug测试,不会产生备份
./ghettoVCB.sh-fvms_to_backup-ddryrun
|
3. 操作范例
在了解相关参数和设定之后,就用一个比较简单的范例来实作一次。
以下的操作请都在「lamw-ghettoVCB-518cef7」资料夹内操作
3.1建立备份List表
在开始操作之前,先来建立vms_to_backup
List的名称可自己设定
1
2
3
|
~ # vi vms_to_backup
#加入要指定的虚拟机名称
Linux
|
3.2 Debug 测试备份
用来排除故障是相当好用的
此模式执行后会提供更详细的讯息,内容包括备份档案和LOG存放的路径,以及备份使用到的空间相关讯息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
~# ./ghettoVCB.sh -f vms_to_backup -d debug
Loggingoutputto"/tmp/ghettoVCB-2012-10-16_13-20-15.log"...
Insufficientarguments.
2012-10-1613:20:15--info:==========ghettoVCBLOGSTART===========
2012-10-1613:20:15--debug:Succesfullyacquiredlockdirectory–/tmp/ghettoVCB.lock
2012-10-1613:20:15--debug:HOSTVERSION:VMwareESXi5.0.0build-469512
2012-10-1613:20:15--debug:HOSTLEVEL:VMwareESXi5.0.0GA
2012-10-1613:20:16--debug:HOSTNAME:localhost
2012-10-1613:20:16--info:CONFIG-VERSION=2012_10_16_1
2012-10-1613:20:16--info:CONFIG-GHETTOVCB_PID=450122
2012-10-1613:20:16--info:CONFIG-VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/backup/backup
2012-10-1613:20:16--info:CONFIG-VM_BACKUP_ROTATION_COUNT=3
2012-10-1613:20:16--info:CONFIG-VM_BACKUP_DIR_NAMING_CONVENTION
=2011-12-27_13-37-15
2012-10-1613:20:16--info:CONFIG-DISK_BACKUP_FORMAT=thin
2012-10-1613:20:16--info:CONFIG-POWER_VM_DOWN_BEFORE_BACKUP=0
2012-10-1613:20:16--info:CONFIG-ENABLE_HARD_POWER_OFF=0
2012-10-1613:20:16--info:CONFIG-ITER_TO_WAIT_SHUTDOWN=3
2012-10-1613:20:16--info:CONFIG-POWER_DOWN_TIMEOUT=5
2012-10-1613:20:16--info:CONFIG-SNAPSHOT_TIMEOUT=15
2012-10-1613:20:16--info:CONFIG-LOG_LEVEL=debug
2012-10-1613:20:16--info:CONFIG-BACKUP_LOG_OUTPUT=/tmp/ghettoVCB-2011-12-27_13-37-15.log
2012-10-1613:20:16--info:CONFIG-VM_SNAPSHOT_MEMORY=0
2012-10-1613:20:16--info:CONFIG-VM_SNAPSHOT_QUIESCE=0
2012-10-1613:20:16--info:CONFIG-VMDK_FILES_TO_BACKUP=all
2012-10-1613:20:16--info:CONFIG-EMAIL_LOG=0
2012-10-1613:20:16--info:
2012-10-1613:20:19--debug:StorageInformationbeforebackup:
2012-10-1613:20:19--debug:SRC_DATASTORE:datastore1
2012-10-1613:20:19--debug:SRC_DATASTORE_CAPACITY:267.2GB
2012-10-1613:20:19--debug:SRC_DATASTORE_FREE:146.2GB
2012-10-1613:20:19--debug:SRC_DATASTORE_BLOCKSIZE:1
2012-10-1613:20:19--debug:SRC_DATASTORE_MAX_FILE_SIZE:256GB
2012-10-1613:20:19--debug:
2012-10-1613:20:19--debug:DST_DATASTORE:datastore1
2012-10-1613:20:19--debug:DST_DATASTORE_CAPACITY:267.2GB
2012-10-1613:20:19--debug:DST_DATASTORE_FREE:146.2GB
2012-10-1613:20:19--debug:DST_DATASTORE_BLOCKSIZE:1
2012-10-1613:20:19--debug:DST_DATASTORE_MAX_FILE_SIZE:256GB
2012-10-1613:20:19--debug:
2012-10-1613:20:19--debug:getVMDKs()-linux.vmdk###100:
2012-10-1613:20:19--info:Initiatebackupforlinux
2012-10-1613:20:19--info:CreatingSnapshot"ghettoVCB-snapshot-2012-10-16"forlinux
2012-10-1613:
|