otrdiena, 2012. gada 6. novembris

Backup virtual machine on ESXi 5 free to NFS storage

Here is a task. I have to made backups of windows web server on free esxi 5 server, backups must be 5 working days, and must be as small as possible. I have ESXi 5 installed. Windows server have VMware tools installed, so there wont be problems with restart. Last time I wrote about backup of windows web server on VMware ESXi 4, on version 5 it is slightly different. You need Linux machine, where to place scripts, generate keys and copy backups.
I go to backup manager and get time frame- when I can copy 100 Gigs via network, he says at 4 o'clock morning and he mades NFS accessible from VMware server. Here is printscreen, you figure it out.

Create folders on backup server for Monday, Tuesday etc
Generate key pair.
ssh-keygen -t rsa -f server3 -N ''
Notice empty quotes at the end, otherwise key will be generated with password
Write some script to create backup which does:
  1. Shutdown virtual machine
  2. Copy all but disks
  3. Clone disks
  4. Power on virtual machine
If vmware tools are not installed, you can shutdown within virtual machine and then start it with backup script.
Test that script. Here is my script

ssh -i server3 root@10.21.1.1 vim-cmd vmsvc/power.shutdown 23
# erase old backup
ssh -i server3 root@10.21.1.1 rm -f /vmfs/volumes/Backup/vm2/*
ssh -i server3 root@10.21.1.1 cp /vmfs/volumes/datastore2/server3/server3.vmx /vmfs/volumes/Backup/vm2/
# wait until vm turns off
sleep 300
ssh -i server3 root@10.21.1.1 vmkfstools -i /vmfs/volumes/datastore2/server3/server3_1.vmdk -d thin /vmfs/volumes/Backup/vm2/server3_1.vmdk
ssh -i server3 root@10.21.1.1 vim-cmd vmsvc/power.on 23
Where server3 are servername to backup.
Copy backups  to backup server
Create crontab task. crontab -e works fine. Here is output of my crontab -l  command

On Tuesday night 3:30 AM will be created Monday backup etc.
Script can be placed on backup server or on administrator machine, I think better to place on backup server and keep copy on administrator machine or you just have one more point of failure. Then you have to check mails on your backup server, crontab sends results to mail@localhost, can be seen typing mail and then number of mail.

Nav komentāru:

Ierakstīt komentāru