How do I backup individual esxi hosts

Using the vMA you can backup and restore individual ESXi hosts using the vicfg-cfgbackup  command.   If you log into your vMA and type vicfg-cfg-backup –help you get some of the following information:

Synopsis: /usr/bin/vicfg-cfgbackup OPTIONS [<backupfile>]

Command-specific options:
 Force the restore of the configuration.
 Restore configuration onto the host
 Do not prompt for user confirmation.
 Resets host, restore to factory settings.
 -s Backup the host configuration.

So in order to backup your ESXi host you just need to select a host and do a -s.  I like to do these sort of things automatically.   Here is my setup:

  • Create a location for backups
mkdir ~/backup
  • Create a script to do backups
# Script created by Joseph Griffiths
# Date to create a unique file
date=`/bin/date '+%m-%d-%y-%H-%M'`;
# Directory to put the backup
# How many days we should keep backups
# Function to do backup
function backup(){
/opt/vmware/vma/bin/vifptarget -s $1
/usr/bin/vicfg-cfgbackup -s $backupdir/$1-$date.bak
# Do the backup
backup "esxi01.vclass.local";
backup "esxi02.vclass.local";
# Clean up
find $backupdir -mtime +$days -exec rm -rf {} \;

Well we want to run this automatically each day correct?  We can do that with crontab lets set it for 2 am everyday

crontab -e

Enter the following:

0 2 * * * /home/vi-admin/ > /dev/null 2>&1

What about restoring?

It’s done with the same command except the -f for force and -l for load

vicfg-cfgbackup -f -l filename

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.