Automated Virtual Machine Backups

From TGITMW
Jump to: navigation, search

The following guide can be used to automate virtual machine backups on ESXi 4.x and up.

Back to Main Page.

Contents


Preparation

1. Create a 'BACKUPS' folder in your datastore. 2. Enable (SSH) in esxi firewall.

  • In your esxi cosole, navigate to the configuration tab and select the security profile menu item under 'Software'.
  • Click on 'Properties' to enable remote tech support mode.

3. Download the ghettoVCB files [1] and extract and upload to your ESXi system in /vmfs/volumes/datastore1/ (use WinSCP to transfer the file) 4. Re-name the directory to 'ghettoVCB'.

5. Set script to executable:
chmod 755 /vmfs/volumes/datastore1/ghettoVCB/ghettoVCB.sh

Configurations

1. Edit the following in the /ghettoVCB/ghettoVCB.sh file:

# directory that all VM backups should go (e.g. /vmfs/volumes/SAN_LUN1/mybackupdir)
VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/BACKUPS

2. Create a file in /ghettoVCB called vms_to_backup and insert the names of your virtual machines, each on a new line as they are listed in your console.


Sample Execution

1. In your terminal window enter (after the #):

~ # cd /vmfs/volumes/datastore1/ghettoVCB/
/vmfs/volumes/datastore1/ghettoVCB/ # ./ghettoVCB.sh -f vms_to_backup -d dryrun
  • This will not backup anything. It will just create log as if it did.

2. Check the logs in the /tmp folder

CRONTAB

1. Setup the cronjob by appending the following line to /var/spool/cron/crontabs/root:

0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log
  • This will run the cronjob at 1am Monday to Friday.

2. For esxi 4.x - Kill the current crond (cron daemon) and then restart the crond for the changes to take affect:

~ # kill $(cat /var/run/crond.pid)
~ # busybox crond

OR for esxi 5.x and up:

~ # kill $(cat /var/run/crond.pid)
~ # /usr/lib/vmware/busybox/bin/busybox crond

3. For esxi 4.x - Now that the cronjob is ready to go, you need to ensure that this cronjob will persist through a reboot. You'll need to add the following lines to /etc/rc.local AFTER the last 'fi' line:

/bin/kill $(cat /var/run/crond.pid)
/bin/echo "0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond

OR for esxi 5.x and up: you'll need to add the following lines to /etc/rc.local.d/local.sh BEFORE the 'exit 0' line:

/bin/kill $(cat /var/run/crond.pid)
/bin/echo "0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log" >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond

4. To ensure that this is saved in the ESXi configuration, we need to manually initiate the esxi backup schedule by running:

~ # /sbin/auto-backup.sh

Testing

Test the script by entering the following at the shell prompt:

~ #  /vmfs/volumes/datastore1/ghettoVCB/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log
Personal tools