vmware esxi 免費的排程的備份還原機制

備份看這兒 
把檔案下載下來後做解壓縮,放到 esxi 中,給執行的權限
  • ghettovcb.sh +x
vi ghettovcb.sh 
  1. 修改 VM_BACKUP_VOLUME=到指定的備份位置 (我掛了一個備份用的 nfs 在 esxi,然後再指定目錄 /vmfs/volumes/nfs 到 ghettovcb.sh 中,要確定這個目錄可以被寫入,nfs分享參數用rw,async,有async速度快很多)
  2. 修改 VM_BACKUP_ROTATION_COUNT=備份保留的份數,預設是3
  3. 修改 email 訊息 改成自己
vi 一個list放guest的名字 (一行放一個vm名字)

執行./ghettovcb.sh -f list -d dryrun 可以做測式
./ghettovcb.sh -f list 則正式備份
-g可以強制讀某一ghettovcb.conf的位置
-a可以全部備份

esxi的排程檔放在 /var/spool/cron/crontabs/root,vi它做排程備份 -->fail 因為readonly,所以要借下面的 rc.local 設定來改排程

vi /etc/rc.local,在最尾加這些code (NOTE:使用排程時一定要將輸出導走,不然可能因為buffer滿了,而導致備份失敗)
  • /bin/kill $(cat /var/run/crond.pid) 
  • /bin/echo "23 16 3 * * /etc/ghettoVCB/ghettoVCB.sh -a > /tmp/ghettoVCB.log" >> /var/spool/cron/crontabs/root 
  • /bin/busybox crond
備份的注意事項
  1. 上面 rc.local 設定重開機才會生效
  2. 備份的時間是utc所以和台北時間差8小時,16:23+8hr是台灣的過一天的00:23,為OK的離峰時間 
  3. guest不能有snapshot,有的話會備份失敗


還原看這兒
使用的備份時已放上的 ghettoVCB-restore.sh,esxi 要 mount 備份資料 nfs,putty 到 esxi 再cd 到nfs中,找到還原指令 ghettoVCB-restore.sh,編修一個還原的vm list,存檔 vms_to_restore,內容示例如下(請修改成自己的主機位置與備份內容)
  • "/vmfs/volumes/601ce787-c96c6cb3/cacti/cacti-2012-05-01_16-23-01;/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti"
執行./ghettoVCB-restore.sh -c vms_to_restore -l vms_restore.log,進行還原

還原錯誤1:
/vmfs/volumes/601ce787-c96c6cb3/ghettoVCB/ghettoVCB-restore # cat vms_restore.log
  • ERROR: Unable to verify datastore locateion: "/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti"! Ensure this exists
這是因為目的地的folder 未建,重新建在還原後,會在目錄下多一層備份時的目錄名,可以考慮將還原目錄指到 datastore1 中就好,感覺比較清爽,當然不做也沒關係
/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti # ls -al
drwxr-xr-x    1 root     root                420 May  3 09:54 .
drwxr-xr-t    1 root     root               1540 May  3 09:53 ..
drwxr-xr-x    1 root     root                840 May  3 10:16 cacti-2012-05-01_16-23-01
/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti # cd cacti-2012-05-01_16-23-01/
/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti/cacti-2012-05-01_16-23-01 # ls -al
drwxr-xr-x    1 root     root                840 May  3 10:16 .
drwxr-xr-x    1 root     root                420 May  3 09:54 ..
-rw-r--r--    1 root     root                  0 May  3 09:54 cacti.vmsd
-rwxr-xr-x    1 root     root               2871 May  3 09:55 cacti.vmx
-rw-r--r--    1 root     root                260 May  3 09:55 cacti.vmxf
-rw-r--r--    1 root     root              30185 May  3 10:16 vmware.log

成功:
/vmfs/volumes/601ce787-c96c6cb3/ghettoVCB/ghettoVCB-restore # ./ghettoVCB-restore.sh -c vms_to_restore -l vms_restore.log
Logging output to "vms_restore.log" ...
sh: 1: unknown operand
sh: 2: unknown operand
sh: 3: unknown operand
sh: 4: unknown operand
64

/vmfs/volumes/601ce787-c96c6cb3/ghettoVCB/ghettoVCB-restore # cat vms_restore.log
################## Restoring VM: cacti  #####################
Start time: Thu May  3 09:54:58 UTC 2012
Restoring VM from: "/vmfs/volumes/601ce787-c96c6cb3/cacti/cacti-2012-05-01_16-23-01"
Restoring VM to Datastore: "/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti" using Disk Format: ""
Creating VM directory: "/vmfs/volumes/4f632a62-5cf36200-e422-001b78e2c544/cacti/cacti-2012-05-01_16-23-01" ...
Copying "cacti.vmx" file ...
Restoring VM's VMDK(s) ...
Updating VMDK entry in "cacti.vmx" file ...
Registering cacti ...
End time: Thu May  3 09:55:00 UTC 2012
################## Completed restore for cacti! #####################


Start time: Thu May  3 09:54:58 UTC 2012
End   time: Thu May  3 09:55:00 UTC 2012
Duration  : 2 Seconds


留言

熱門文章