更新日期: 2012.10.17
最新內容更新請參考此篇 [VMware ESXi 備份 ghettoVCB.sh 基本設定]
一、 ghettoVCB.sh 介紹
此腳本主要是用來做VM ESXI備份使用。目前所能使用的版本有,ESX(i)3.5/4.x/5.x,使用的方法類似VMware的VCB的工具執行備份。ghettoVCB.sh該腳本是執行虛擬機的快照,然後進行備份,當備份完成後會刪除快照。而此腳本最大的特色為可在虛擬機在線時備份,而不用停機備份。
詳細內容可參考 VMware官網
二、 ghettoVCB.sh安裝設定說明
1. 前置作業(上傳檔案和開啟SSH)
1.1 上傳檔案
1.1.1 下載ghettoVCB.sh 會有兩種下載方式。請依各人需要下載
在這邊下載tar.gz為範例
1.1.2 上傳lamw-ghettoVCB-518cef7.tar
把剛剛下載好的lamw-ghettoVCB-518cef7.tar上傳到esxi。
上傳的方式有WinSCP或是使用VMware vSphere Client上傳等方式
在這邊用VMware vSphere Client上傳
[Configuration]→[Storage]→[datastore1]→[Browse Datastore]
1.1.3 先選擇檔案要存放的路徑,然後點,選Upload File
當檔案上傳完成,就會看到多一個上傳好的lamw-ghettoVCB-518cef7.tar
1.2 開啟SSH
[Configuration]→[Security Profile]→[Properties]
[SSH]→[Options]→[Start]
2. ghettoVCB.sh安裝與設定
在開始安裝之前有一點要注意一下
由於esxi在重開機之後會把某些資料刪除,因此會建議把此檔留在datastore1此硬碟空間內,才不會因重開機後檔案就被刪除了。
2.1 安裝
基本上datastore1此空間的路徑為/vmfs/volumes/datastore1
解tar後會看到ghettoVCB.sh,此腳本正是所需要的
~ # 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 基本ghettoVCB.sh設定說明
以下說明 基本常用到的設定。
~ # vi ghettoVCB.sh
#設定備份所存放的路徑,在這邊設定備份到本地端 VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/backup
#定義被份的硬碟格式(zeroedthick, eagerzeroedthick, thin, and 2gbsparse are available) #若想更了解硬碟格式說明請參考「VMware ESX(i)虛擬磁碟格式介紹」 DISK_BACKUP_FORMAT=thin
#定義備份保留的數量 VM_BACKUP_ROTATION_COUNT=3
#虛擬機POWER OFF時不會要求snapshoting (enable=1,disable=0) POWER_VM_DOWN_BEFORE_BACKUP=0
#定義沒有安裝VMware Tools的虛擬機是否可以在硬碟POWER OFF時啟用”POWER_VM_DOWN_BEFORE_BACKUP” ENABLE_HARD_POWER_OFF=0
#如果啟用”ENABLE_HARD_POWER_OFF”則此定義腳本執行強制關閉時(60秒)倒數運算 ITER_TO_WAIT_SHUTDOWN=3
#設定POWER DOWN的時間。在等待關閉時VM會放棄或是忽略特定的VM備份 POWER_DOWN_TIMEOUT=5
#設定等待VM快照的時間,在等待關閉時會放棄和忽略特定備份的VM SNAPSHOT_TIMEOUT=15
#備份是否啟用壓縮(enable=1,disable=0) ENABLE_COMPRESSION=0
#定義虛擬機的記憶體是否snapped和是否啟用quiescing(enable=1,disable=0) VM_SNAPSHOT_MEMORY=0 VM_SNAPSHOT_QUIESCE=0
#接下來為NFS的相關設定 #定義非持久性的NFS備份 ENABLE_NON_PERSISTENT_NFS=0
#以下是給不想讓NFS與系統長期連接的設定。允許只在備份的過程中連接到NFS, 並使用到以下5個變數。 #是否要卸載NFS(yes=1,no=0) UNMOUNT_NFS=0
#NFS Server 的地址(ip或主機名) NFS_SERVER=172.30.0.195
#NFS 存放檔案的路徑 NFS_MOUNT=/nfsshare
#NFS 資料存放地方的名稱 NFS_LOCAL_NAME=nfs_storage_backup
#虛擬機上NFS備份的目錄 NFS_VM_BACKUP_DIR=mybackups
#以下是MAIL 發送LOG的設定 #是否要透過電子郵件來發送備份LOG(yes=1,no=0) EMAIL_LOG=1
#是否發送debug的LOG,這是做為測試使用。 EMAIL_DEBUG=1
#mail server的ip或網址 EMAIL_SERVER=auroa.primp-industries.com
#設定mail 所使用的port EMAIL_SERVER_PORT=25
#設定每封mail之間發送的延遲時間。 EMAIL_DELAY_INTERVAL=1
#收件人的mail EMAIL_TO=auroa@primp-industries.com
#寄件人的mail EMAIL_FROM=root@ghettoVCB |
3. ghettoVCB.sh參數說明
~ # ./ghettoVCB.sh
Logging output to “/tmp/ghettoVCB-2011-12-18_17-32-09.log” … 2011-12-18 17:32:10 – info: ERROR: Incorrect number of arguments! ########################################################### # # 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 Backup all VMs on host (備份主機上所有的虛擬機) -f List of VMs to backup (針對List名單內的虛擬機備份) -c VM configuration directory for VM backups (VM 配置目錄for VM備份) -g Path to global ghettoVCB configuration file -l File to output logging (將LOG記錄寫到指定檔案內) -d Debug level [info|debug|dryrun] (default: info) (Debug測試,不會產生備份)
(e.g.)
Backup VMs stored in a list 只備份list內的虛擬機 ./ghettoVCB.sh -f vms_to_backup
Backup all VMs residing on this host 全部備份 ./ghettoVCB.sh -a
Backup all VMs residing on this host except for the VMs in the exclusion list 除了排除清單(vm_exclusion_list)上的虛擬機外,剩下的都備份 ./ghettoVCB.sh -a -e vm_exclusion_list
Backup VMs based on specific configuration located in directory 根據vm_backup_configs中特定配置來備份vms_to_backup內指定的虛擬機 ./ghettoVCB.sh -f vms_to_backup -c vm_backup_configs
Backup VMs using global ghettoVCB configuration file 備份虛擬機時使用ghettoVCB.conf此設定檔來備份vms_to_backup內指定的虛擬機 ./ghettoVCB.sh -f vms_to_backup -g /global/ghettoVCB.conf
Output will log to /tmp/ghettoVCB.log (consider logging to local or remote datastore to persist logs) 輸出的記錄到/tmp/ghettoVCB.log(可自行設定LOG所儲存的路徑和檔案) ./ghettoVCB.sh -f vms_to_backup -l /vmfs/volume/local-storage/ghettoVCB.log
Dry run (no backup will take place) Debug測試,不會產生備份 ./ghettoVCB.sh -f vms_to_backup -d dryrun |
4. 範例操作
4.1 建立List vms_to_backup
在開始操作之前,先來建立vms_to_backup
List的名稱可自己設定
~ # vi vms_to_backup
#加入要指定的虛擬機名稱 linux |
4.2 Dry run測試,不會產生備份
以下有幾個比較需要知道的部份會已黃色字體標示
在預設定情況下log都是存放在/tmp內,若是有需要保留log的話請參考下方設定來修改log存放處,避免重開機後log會被清除
~ # ./ghettoVCB.sh -f vms_to_backup -d dryrun
Logging output to “/tmp/ghettoVCB-2011-12-27_13-23-26.log” … #備份LOG存放的地方 Insufficient arguments. 2011-12-27 13:23:26 — info: =========== ghettoVCB LOG START ============ 2011-12-27 13:23:26 — info: CONFIG – VERSION = 2011_11_19_1 2011-12-27 13:23:26 — info: CONFIG – GHETTOVCB_PID = 449441 2011-12-27 13:23:26 — info: CONFIG – VM_BACKUP_VOLUME = /vmfs/volumes/datastore1/backup/backup 2011-12-27 13:23:26 — info: CONFIG – VM_BACKUP_ROTATION_COUNT = 3 2011-12-27 13:23:26 — info: CONFIG – VM_BACKUP_DIR_NAMING_CONVENTION = 2011-12-27_13-23-26 2011-12-27 13:23:26 — info: CONFIG – DISK_BACKUP_FORMAT = thin 2011-12-27 13:23:26 — info: CONFIG – POWER_VM_DOWN_BEFORE_BACKUP = 0 2011-12-27 13:23:26 — info: CONFIG – ENABLE_HARD_POWER_OFF = 0 2011-12-27 13:23:26 — info: CONFIG – ITER_TO_WAIT_SHUTDOWN = 3 2011-12-27 13:23:26 — info: CONFIG – POWER_DOWN_TIMEOUT = 5 2011-12-27 13:23:26 — info: CONFIG – SNAPSHOT_TIMEOUT = 15 2011-12-27 13:23:26 — info: CONFIG – LOG_LEVEL = dryrun 2011-12-27 13:23:26 — info: CONFIG – BACKUP_LOG_OUTPUT = /tmp/ghettoVCB-2011-12-27_13-23-26.log #備份LOG所存放的地方 2011-12-27 13:23:26 — info: CONFIG – VM_SNAPSHOT_MEMORY = 0 2011-12-27 13:23:26 — info: CONFIG – VM_SNAPSHOT_QUIESCE = 0 2011-12-27 13:23:26 — info: CONFIG – VMDK_FILES_TO_BACKUP = all 2011-12-27 13:23:26 — info: CONFIG – EMAIL_LOG = 0 2011-12-27 13:23:26 — info: 2011-12-27 13:23:27 — dryrun: ############################################### 2011-12-27 13:23:27 — dryrun: Virtual Machine: linux 2011-12-27 13:23:27 — dryrun: VM_ID: 1 2011-12-27 13:23:27 — dryrun: VMX_PATH: /vmfs/volumes/datastore1/linux/linux.vmx 2011-12-27 13:23:27 — dryrun: VMX_DIR: /vmfs/volumes/datastore1/linux 2011-12-27 13:23:27 — dryrun: VMX_CONF: linux/linux.vmx 2011-12-27 13:23:27 — dryrun: VMFS_VOLUME: datastore1 2011-12-27 13:23:27 — dryrun: VMDK(s): 2011-12-27 13:23:27 — dryrun: linux.vmdk 100 GB #備份VM的大小 2011-12-27 13:23:27 — dryrun: INDEPENDENT VMDK(s): 2011-12-27 13:23:27 — dryrun: TOTAL_VM_SIZE_TO_BACKUP: 100 GB #總備份的大小 2011-12-27 13:23:27 — dryrun: ###############################################
2011-12-27 13:23:27 — info: ###### Final status: OK, only a dryrun. ###### #測試是否OK,並告知此次只有dryrun 2011-12-27 13:23:27 — info: ==========ghettoVCB LOG END ============= |
4.3 Debug 測試備份
此模式執行後會提供更詳細的訊息,內容包括備份檔案和LOG存放的路徑,以及備份使用到的空間相關訊息。對用來排除故障是相當好用的
~ # ./ghettoVCB.sh -f vms_to_backup -d debug
Logging output to “/tmp/ghettoVCB-2011-12-27_13-37-15.log” … Insufficient arguments. 2011-12-27 13:37:15 — info: ========== ghettoVCB LOG START=========== 2011-12-27 13:37:15 — debug: Succesfully acquired lock directory – /tmp/ghettoVCB.lock 2011-12-27 13:37:15 — debug: HOST VERSION: VMware ESXi 5.0.0 build-469512 2011-12-27 13:37:15 — debug: HOST LEVEL: VMware ESXi 5.0.0 GA 2011-12-27 13:37:16 — debug: HOSTNAME: localhost
2011-12-27 13:37:16 — info: CONFIG – VERSION = 2011_11_19_1 2011-12-27 13:37:16 — info: CONFIG – GHETTOVCB_PID = 450122 2011-12-27 13:37:16 — info: CONFIG – VM_BACKUP_VOLUME = /vmfs/volumes/datastore1/backup/backup 2011-12-27 13:37:16 — info: CONFIG – VM_BACKUP_ROTATION_COUNT = 3 2011-12-27 13:37:16 — info: CONFIG – VM_BACKUP_DIR_NAMING_CONVENTION = 2011-12-27_13-37-15 2011-12-27 13:37:16 — info: CONFIG – DISK_BACKUP_FORMAT = thin 2011-12-27 13:37:16 — info: CONFIG – POWER_VM_DOWN_BEFORE_BACKUP = 0 2011-12-27 13:37:16 — info: CONFIG – ENABLE_HARD_POWER_OFF = 0 2011-12-27 13:37:16 — info: CONFIG – ITER_TO_WAIT_SHUTDOWN = 3 2011-12-27 13:37:16 — info: CONFIG – POWER_DOWN_TIMEOUT = 5 2011-12-27 13:37:16 — info: CONFIG – SNAPSHOT_TIMEOUT = 15 2011-12-27 13:37:16 — info: CONFIG – LOG_LEVEL = debug 2011-12-27 13:37:16 — info: CONFIG – BACKUP_LOG_OUTPUT = /tmp/ghettoVCB-2011-12-27_13-37-15.log 2011-12-27 13:37:16 — info: CONFIG – VM_SNAPSHOT_MEMORY = 0 2011-12-27 13:37:16 — info: CONFIG – VM_SNAPSHOT_QUIESCE = 0 2011-12-27 13:37:16 — info: CONFIG – VMDK_FILES_TO_BACKUP = all 2011-12-27 13:37:16 — info: CONFIG – EMAIL_LOG = 0 2011-12-27 13:37:16 — info: 2011-12-27 13:37:19 — debug: Storage Information before backup: 2011-12-27 13:37:19 — debug: SRC_DATASTORE: datastore1 2011-12-27 13:37:19 — debug: SRC_DATASTORE_CAPACITY: 267.2 GB 2011-12-27 13:37:19 — debug: SRC_DATASTORE_FREE: 146.2 GB 2011-12-27 13:37:19 — debug: SRC_DATASTORE_BLOCKSIZE: 1 2011-12-27 13:37:19 — debug: SRC_DATASTORE_MAX_FILE_SIZE: 256 GB 2011-12-27 13:37:19 — debug: 2011-12-27 13:37:19 — debug: DST_DATASTORE: datastore1 2011-12-27 13:37:19 — debug: DST_DATASTORE_CAPACITY: 267.2 GB 2011-12-27 13:37:19 — debug: DST_DATASTORE_FREE: 146.2 GB 2011-12-27 13:37:19 — debug: DST_DATASTORE_BLOCKSIZE: 1 2011-12-27 13:37:19 — debug: DST_DATASTORE_MAX_FILE_SIZE: 256 GB 2011-12-27 13:37:19 — debug: 2011-12-27 13:37:19 — debug: getVMDKs() – linux.vmdk###100: 2011-12-27 13:37:19 — info: Initiate backup for linux 2011-12-27 13:37:19 — info: Creating Snapshot “ghettoVCB-snapshot-2011-12-27″ for linux 2011-12-27 13:37:21 — debug: Waiting for snapshot “ghettoVCB-snapshot-2011-12-27″ to be created 2011-12-27 13:37:21 — debug: Snapshot timeout set to: 900 seconds 2011-12-27 13:37:22 — debug: findVMDK() – Searching for VMDK: “linux.vmdk” to backup 2011-12-27 13:37:22 — debug: /sbin/vmkfstools -i “/vmfs/volumes/datastore1/linux/linux.vmdk” -a “lsilogic” -d “thin” “/vmfs/volumes/datastore1/backup/backup/linux/linux-2011-12-27_13-37-15/linux.vmdk” Destination disk format: VMFS thin-provisioned Cloning disk ‘/vmfs/volumes/datastore1/linux/linux.vmdk’… Clone: 94% done. 2011-12-27 13:38:19 — info: Removing snapshot from linux … 2011-12-27 13:38:19 — info: Backup Duration: 60 Seconds 2011-12-27 13:38:19 — info: Successfully completed backup for linux!
2011-12-27 13:38:21 — debug: Storage Information after backup: 2011-12-27 13:38:21 — debug: SRC_DATASTORE: datastore1 2011-12-27 13:38:21 — debug: SRC_DATASTORE_CAPACITY: 267.2 GB 2011-12-27 13:38:21 — debug: SRC_DATASTORE_FREE: 146.2 GB 2011-12-27 13:38:21 — debug: SRC_DATASTORE_BLOCKSIZE: 1 2011-12-27 13:38:21 — debug: SRC_DATASTORE_MAX_FILE_SIZE: 256 GB 2011-12-27 13:38:21 — debug: 2011-12-27 13:38:21 — debug: DST_DATASTORE: datastore1 2011-12-27 13:38:21 — debug: DST_DATASTORE_CAPACITY: 267.2 GB 2011-12-27 13:38:21 — debug: DST_DATASTORE_FREE: 146.2 GB 2011-12-27 13:38:21 — debug: DST_DATASTORE_BLOCKSIZE: 1 2011-12-27 13:38:21 — debug: DST_DATASTORE_MAX_FILE_SIZE: 256 GB 2011-12-27 13:38:21 — debug: 2011-12-27 13:38:21 — info: ###### Final status: All VMs backed up OK! ######
2011-12-27 13:38:21 — debug: Succesfully removed lock directory – /tmp/ghettoVCB.lock
2011-12-27 13:38:21 — info: ===========ghettoVCB LOG END============= |
4.4 針對list(vms_to_backup)中指定的VM虛擬機進行備份
~ # ./ghettoVCB.sh -f vms_to_backup |
4.5 備份所有的VM虛擬機
~ # ./ghettoVCB.sh -a |
4.6 排除list中指定的VM虛擬機不進行備份外,其他全部備份
~ # vi vm_exclusion_list
#加入要指定排除的虛擬機名稱 linux ~ # ./ghettoVCB.sh -a -e vm_exclusion_list |
如果想更加了解 VMware esx ( i ) ghettoVCB 的進階使用方式可參考下面的文章
VMware esxi 備份ghettoVCB.sh進階設定說明
ghettoVCB備份 錯誤訊息 Snapshot found for「host」, backup will not take place
VMware esxi 備份還原ghettoVCB-restore.sh 設定說明
VMware ESX(i)使用VMware vSphere Client做OVF備份與還原
評論
此文章尚無評論。