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
 -f
 Force the restore of the configuration.
 --load
 -l
 Restore configuration onto the host
 --quiet
 -q
 Do not prompt for user confirmation.
 --reset
 -r
 Resets host, restore to factory settings.
 --save
 -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
#!/bin/bash
# Script created by Joseph Griffiths
# bloodygranola.com
# Date to create a unique file
date=`/bin/date '+%m-%d-%y-%H-%M'`;
# Directory to put the backup
backupdir="/home/vi-admin/backup"
# How many days we should keep backups
days="30"
# 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/backup.sh > /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.

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