Archive for July, 2014

VMware free backup solution from virtuallyGhetto

Backup:

VMware free backup solution for ESXi servers: https://communities.vmware.com/docs/DOC-8760

Download the script from github: https://github.com/lamw/ghettoVCB then modify it for your system to fit in.

I’m going to explain the important parts that I usually change in this script:

In ghettoVCB.sh file:

– Backup path
– Rotation
– Backup format
– Email server
– Email to
– Email from

1: 

# directory that all VM backups should go (e.g. /vmfs/volumes/SAN_LUN1/mybackupdir)
VM_BACKUP_VOLUME=/vmfs/volumes/NAS-Fuji/backup

2:

# Format output of VMDK backup
# zeroedthick
# 2gbsparse
# thin
# eagerzeroedthick
DISK_BACKUP_FORMAT=thin

3:

# Number of backups for a given VM before deleting
VM_BACKUP_ROTATION_COUNT=3

Also in ghettoVCB.conf

VM_BACKUP_VOLUME=/vmfs/volumes/NAS-Fuji
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=3

4:

EMAIL_SERVER=10.0.100.10

5:

EMAIL_TO=lszabo@7layer.org

6:

EMAIL_FROM=root@ghettoVCB

When you uploaded the ghettovcb.sh and ghettovcb.conf files you need to add execute flag to the ghettoVCB.sh file:

chmod +x ghettoVCB.sh

Then you can start backing up your VM machines.

Backup only one machine run this:

./ghettoVCB.sh -m vm_to_backup

Backup all machines:

./ghettoVCB.sh -a

If you want to machine to be avoided from backup then use an except file to achive this:
./ghettoVCB.sh -a -e vm_exclusion_list

VMware firewall wont let allow to send outgoing emails from the script, this need to be fixed.
Upload smtp.xml file to VMware server and update the firewall, with out this you will receive an error on VMware ssh console.

Script:  smtp.xml

Upload it to /etc/vmware/firewall and run esxcli update:

esxcli network firewall refresh

Then click on server name, configuration, security profile and you will see the new smtp outbond port appeared as a new outgoing firewall rule to allow smtp outgoing traffic from the server.

backup-smtp

 



Restore:

Altough you can use the restore script: https://communities.vmware.com/docs/DOC-10595 to restore machines from backup, but you can use them straight away when you add to your machine from the backup script.
This is much quicker then the restore process, but obviously the machine will reside on the backup path not on the original path. With this you can get back the machine ASAP, then create a backup onto the original path and shut down the backup path machine and add to the inventory the original path machine and start it up.

backup

Only one thing left to do is to make this process be automatic.
Edit crontab on your server and add this to it:
10 00 * * 1-5 /vmfs/volumes/ghettoVCB.sh -f /vmfs/volumes/Fuji-NAS/backuplist > /vmfs/volumes/ghettoVCB-backup-$(date +\%s).log

Crontab file located on VMware ESXi 5.5 at: /var/spool/crontabs/ and root file contains the current configuration for crontab.

cat /var/spool/cron/crontabs/root

#min hour day mon dow command
1 1 * * * /sbin/tmpwatch.py
1 * * * * /sbin/auto-backup.sh
0 * * * * /usr/lib/vmware/vmksummary/log-heartbeat.py
*/5 * * * * /sbin/hostd-probe ++group=host/vim/vmvisor/hostd-probe
10 00 * * 1-5 /vmfs/volumes/datastore1/root/opt/ghettoVCB.sh -f /vmfs/volumes/datastore1/root/opt/vmbackup.txt

This will run backup on every day at 10'o clock, but you can change it according to your needs.
 
Show Buttons
Hide Buttons