ESXI Config Backup Utility

The ESXI Config Backup Utility is a PowerShell script that makes it easy to take config backups of individual ESXI hosts or all of your ESXI hosts by connection to a vCenter appliance. The script also makes it very easy to schedule the backups to run automatically by leveraging Windows Task Scheduler. The script uses VMware PowerCLI to connect to the resource, initiate a backup, and store it on your local machine. The script also includes retention settings in the event you only want to keep a certain number of them on hand.

Available on our Github page.  https://github.com/confusedit/esxi-config-backup-utility

2022-07-17_19-05-53

Features

Requirements

Instructions

The command line flags below can be used to enable the script and/or take backups. Using -Run will bypass any config and give you a "Run Once" experience to take a backup. If you need to edit your configuration, you'll need to run -Disable then -SetConfig then -Enable.

Command Line Flags

-SetCreds - Use to set Host/vCenter credentials.
-SetConfig - Use to set configuration options (IP/Hostname, Backup Schedule, Retention)
-Enable - Use to enable backup schedule.
-Disable - Use to disable backup schedule.

-RunConfig - Use to take backups using your stored credentials and config file.
-Run - Use to take backups without using your config file (you will be prompted for hostname/credentials).

First Step

Download the file, be sure to open up properties on the zipped folder and unblock it. 2022-07-17_18-40-21

Second Step

Open PowerShell window as an administrator, then run the PowerShell script in the window and wait.

./ESXI-Config-Backup-Utility.ps1

It will look for PowerCLI if it doesn't exist it will install it, once it's done, it will take you back to the PowerShell command line.

Last Step

This isn't really the last step, but it's close enough for you to figure it out from here. All you need to do now is use the -Run flag to do a one time backup or use the -SetCreds, -SetConfig, and -Enable flags (in that order) to get it going on a schedule. Before you use -Enable you can use -RunConfig to take a backup using your config to make sure there are no issue.

Notes

Below are some notes/tips that might help.

File Locations

Everything is stored in C:\Scripts\ESXI-Config-Backup-Utility\ this directory is created automatically and is set in the Global Variables part of the script, if you change the location there it might work, I haven't tried it.

Event Logs

For several errors in the script it should create an event log entry in the Windows Event Applications Log under the name ESXI-Config-Backup-Utility, for some reason it shows up in the table view as Backup-Utility, I'm going to try to fix that in the future, if you expland the event details it does show the full name.

Changing Configs

If you want to change your config file you can run -SetConfig as mentioned before, it will take a backup of the existing config and put it in a directory called ConfigBackups with everything else. You'll need to run -Disable then -Enable for the new config to take full effect.

Retention Settings

Retention settings seems to keep one more backup than what you requested. I'm going to look into at some point but for now what it does is if your retention is 3, when a backup is started it will delete the oldest backups so that there are only 3 in the folder, then it will take a backup, at which point you'll now have 4 backups in the folder. If I move the retention part to after the backup takes place that might fix it, I might do that soon.

-Run bypasses retention, only -RunConfig and scheduled backups run retention.

Updates

When new versions are released I would recommend running -Disable, then with the new script version run -Enable, this will copy the new version into the correct location. If you have issues it may be best to just delete all the files in the C:\Scripts\ESXI-Config-Backup-Utility directory and reconfigure the utility. Deleting the directory will not remove the scheduled task in Windows Task Scheduler, you'll need to open up task scheduler and remove it manually or use the -Disable flag to remove it.


Revision #5
Created 17 July 2022 14:04:35 by Mike
Updated 17 July 2022 19:04:06 by Mike