VMWare ghettoVCB.sh Backup

VMware免費並且可線上備份(不須關機)的方式,大概就是ghettoVCB.sh最為好用。
以下為我的設定步驟流程,好讓自己不要忘記。

1. 開啟SSH Service
2.下載ghettoVCB.sh
3. ghettoVCB.sh設定備份
4. 防火牆修改
5. 時區修改
6. 設定排程

1. 開啟SSH Service
Configuration Security Profile Services Properties

SSH Options Start 

SSH 進入系統
登入系統發現時區是UTC,與台灣時區+8不同,可以透過一些方式來改變系統時區

2.下載ghettoVCB.sh
下載路徑如下:
https://github.com/lamw/ghettoVCB
透過Winscp上傳至VMware Host,因為VMware Host 重新開機後會固定把特定檔案恢復,所以我放在我的Local Datastore上,這樣可以避免檔案遺失。

3. ghettoVCB.sh設定備份

設定檔案權限為700

#cd /vmfs/volumes/datastore1/ghettoVCB-master/
#chmod 700 ghettoVCB.sh
#chmod 700 ghettoVCB-restore.sh


我會修改到的檔案內容如下: (其實還很多參數可以調整,這邊是紀錄我自己常用的)

#vi /vmfs/volumes/datastore1/ghettoVCB-master/ghettoVCB.sh
a.  VM_BACKUP_VOLUME=備份路徑

b.  DISK_BACKUP_FORMAT=備份硬碟格式

c.  VM_BACKUP_ROTATION_COUNT=備份數量

d.  EMAIL_LOG=1  (0:disable  1:enable)

e.  EMAIL_SERVER=Mail Server Host

f.  EMAIL_SERVER_PORT=25

g.  EMAIL_FROM=寄件者

h.  EMAIL_TO=收件者

測試備份
Usage: ghettoVCB.sh [options]

OPTIONS:
-a     Backup all VMs on host  (全部備份)
-f     List of VMs to backup (指定List 檔案備份)
-m     Name of VM to backup (overrides -f) (指定VMware 名稱備份)
-c     VM configuration directory for VM backups
-g     Path to global ghettoVCB configuration file
-l     File to output logging (log 外倒預設在/tmp/)
-w     ghettoVCB work directory (default: /tmp/ghettoVCB.work)
-d     Debug level [info|debug|dryrun] (default: info)  (測試備份)

目前有一台Guest OS在這台Host 上

#esxcli vm process list

test2008
World ID: 10758
Process ID: 0
VMX Cartel ID: 10757
UUID: 42 03 44 5b 8d 93 9e ea-4e 7d 33 0b 94 8a b6 e8
Display Name: test2008
Config File: /vmfs/volumes/51ad5de7-376d0ac1-1adc-001b21af457e/test2008/test2008.vmx

執行測試備份

#/vmfs/volumes/datastore1/ghettoVCB-master/ghettoVCB.sh -d dryrun -m test2008

Logging output to “/tmp/ghettoVCB-2013-07-26_06-33-33-11099.log” …
2013-07-26 06:33:34 — info: ============================== ghettoVCB LOG START ==============================

2013-07-26 06:33:34 — info: CONFIG – VERSION = 2013_01_11_0
2013-07-26 06:33:34 — info: CONFIG – GHETTOVCB_PID = 11099
2013-07-26 06:33:34 — info: CONFIG – VM_BACKUP_VOLUME = /vmfs/volumes/XXXXXXXXX
2013-07-26 06:33:34 — info: CONFIG – VM_BACKUP_ROTATION_COUNT = 3
2013-07-26 06:33:34 — info: CONFIG – VM_BACKUP_DIR_NAMING_CONVENTION = 2013-07-26_06-33-33
2013-07-26 06:33:34 — info: CONFIG – DISK_BACKUP_FORMAT = thin
2013-07-26 06:33:34 — info: CONFIG – POWER_VM_DOWN_BEFORE_BACKUP = 0
2013-07-26 06:33:34 — info: CONFIG – ENABLE_HARD_POWER_OFF = 0
2013-07-26 06:33:34 — info: CONFIG – ITER_TO_WAIT_SHUTDOWN = 3
2013-07-26 06:33:34 — info: CONFIG – POWER_DOWN_TIMEOUT = 5
2013-07-26 06:33:34 — info: CONFIG – SNAPSHOT_TIMEOUT = 15
2013-07-26 06:33:34 — info: CONFIG – LOG_LEVEL = dryrun
2013-07-26 06:33:34 — info: CONFIG – BACKUP_LOG_OUTPUT = /tmp/ghettoVCB-2013-07-26_06-33-33-11099.log
2013-07-26 06:33:34 — info: CONFIG – ENABLE_COMPRESSION = 0
2013-07-26 06:33:34 — info: CONFIG – VM_SNAPSHOT_MEMORY = 0
2013-07-26 06:33:34 — info: CONFIG – VM_SNAPSHOT_QUIESCE = 0
2013-07-26 06:33:34 — info: CONFIG – ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP = 0
2013-07-26 06:33:34 — info: CONFIG – VMDK_FILES_TO_BACKUP = all
2013-07-26 06:33:34 — info: CONFIG – VM_SHUTDOWN_ORDER =
2013-07-26 06:33:34 — info: CONFIG – VM_STARTUP_ORDER =
2013-07-26 06:33:34 — info: CONFIG – EMAIL_LOG = 1
2013-07-26 06:33:34 — info: CONFIG – EMAIL_SERVER = XXXXXXXXXXXXXXXX
2013-07-26 06:33:34 — info: CONFIG – EMAIL_SERVER_PORT = 25
2013-07-26 06:33:34 — info: CONFIG – EMAIL_DELAY_INTERVAL = 1
2013-07-26 06:33:34 — info: CONFIG – EMAIL_FROM = XXXXXXXXXXXXXXXXX
2013-07-26 06:33:34 — info: CONFIG – EMAIL_TO =XXXXXXXXXXXXXXX
2013-07-26 06:33:34 — info: CONFIG – WORKDIR_DEBUG = 0
2013-07-26 06:33:34 — info:
2013-07-26 06:33:34 — dryrun: ###############################################
2013-07-26 06:33:34 — dryrun: Virtual Machine: test2008
2013-07-26 06:33:34 — dryrun: VM_ID: 1
2013-07-26 06:33:34 — dryrun: VMX_PATH: /vmfs/volumes/test2008/test2008.vmx
2013-07-26 06:33:34 — dryrun: VMX_DIR: /vmfs/volumes/test2008
2013-07-26 06:33:34 — dryrun: VMX_CONF: test2008/test2008.vmx
2013-07-26 06:33:34 — dryrun: VMFS_VOLUME: XXXXXX
2013-07-26 06:33:34 — dryrun: VMDK(s):
2013-07-26 06:33:34 — dryrun: test2008-000001.vmdk 40 GB
2013-07-26 06:33:34 — dryrun: INDEPENDENT VMDK(s):
2013-07-26 06:33:34 — dryrun: TOTAL_VM_SIZE_TO_BACKUP: 40 GB
2013-07-26 06:33:34 — dryrun: Snapshots found for this VM, please commit all snapshots before continuing!
2013-07-26 06:33:34 — dryrun: THIS VIRTUAL MACHINE WILL NOT BE BACKED UP DUE TO EXISTING SNAPSHOTS!
2013-07-26 06:33:34 — dryrun: ###############################################

2013-07-26 06:33:34 — info: ###### Final status: OK, only a dryrun. ######

2013-07-26 06:33:34 — info: ============================== ghettoVCB LOG END ================================

4. 防火牆修改
因為預設VMware Host SMTP Outgoing會被防火牆阻擋,所以剛剛的測試信件並沒有正常送達
修改防火牆設定如下:
#chmod 644 /etc/vmware/firewall/service.xml
#chmod +t /etc/vmware/firewall/service.xml
#vi /etc/vmware/firewall/service.xml 
 
<service id=”0033″>
 
<id>SMTP</id>
 
<rule id=’0000′>
 
<direction>outbound</direction>
 
<protocol>tcp</protocol>
 
<porttype>dst</porttype>
 
<port>25</port>
 
</rule>
 
<enabled>true</enabled>
 
<required>false</required>
 
</service>
 

 

更新防火牆規則
#esxcli network firewall refresh
測試SMTP Outgoing 是否正常
#nc 192.168.10.50 25
220 localhost.localdomain ESMTP Postfix
#chmod 444 /etc/vmware/firewall/service.xml
複製service.xml
#cp /etc/vmware/firewall/service.xml /vmfs/volumes/datastore1/ghettoVCB-master/
5.時區修改
在測試的時間發現並非台灣CST 時間而是UTC時間,修改方式如下:
找一台Linux 主機上的/etc/localtime 複製到VMware Host
 
#cp /vmfs/volumes/datastore1/ghettoVCB-master/localtime /etc/localtime
#chmod 444 /etc/localtime
確認時區改為CST +8
#date
Fri Jul 26 14:44:13 CST 2013
6.設定排程
設定備份排程檔案(root)
#vi /vmfs/volumes/datastore1/ghettoVCB-master/root
******************************************************************
1    1    *   *   *   /sbin/tmpwatch.py
1    *    *   *   *   /sbin/auto-backup.sh
0    *    *   *   *   /usr/lib/vmware/vmksummary/log-heartbeat.py
5    1   *   *   *   /vmfs/volumes/datastore1/ghettoVCB-master/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB-master/vms_to_backup
******************************************************************
#chmod 744 /vmfs/volumes/datastore1/ghettoVCB-master/root
#vi  /vmfs/volumes/datastore1/ghettoVCB-master/crontab.sh
******************************************************************
#!/bin/sh
/bin/kill $(cat /var/run/crond.pid)
cp /vmfs/volumes/datastore1/ghettoVCB-master/root /var/spool/cron/crontabs
/bin/busybox crond
*******************************************************************
#chmod 755 /vmfs/volumes/datastore1/ghettoVCB-master/crontab.sh
 
#vi /vmfs/volumes/datastore1/ghettoVCB-master/firewall.sh
*******************************************************************
#!/bin/sh
cp /vmfs/volumes/datastore1/ghettoVCB-master/service.xml /etc/vmware/firewall/
esxcli network firewall refresh
*******************************************************************
#chmod 755 /vmfs/volumes/datastore1/ghettoVCB-master/firewall.sh

#vi  /vmfs/volumes/datastore1/ghettoVCB-master/time.sh
*******************************************************************
#!/bin/shcp /vmfs/volumes/datastore1/ghettoVCB-master/localtime /etc/localtime*******************************************************************#chmod 755 /vmfs/volumes/datastore1/ghettoVCB-master/time.sh
 
寫入/etc/rc.local
#vi /etc/rc.local (新增內容)
*******************************************************************
/vmfs/volumes/datastore1/ghettoVCB-master/crontab.sh
 /vmfs/volumes/datastore1/ghettoVCB-master/firewall.sh
/vmfs/volumes/datastore1/ghettoVCB-master/time.sh
*******************************************************************
 
當排程在背景執行時,若想察看進度可執行下列指令查看執行進度
#ps -c | grep ghettoVCB | grep -v grep
最後附上我的參考來源:
Facebook Comments