«

Nov 18

vSphere 6.5 – Automate VCSA Backup

Preface

I recently attended the Orlando VMUG Usercon and had been discussing many of the great features of the vSphere 6.5 release that was announced at VMworld Barcelona. I began to chat with Rob P., an attendee of the conference, about VCSA backup. Paraphrasing part of our chat he asked “I saw that you can backup the VCSA in the announcements. Is there an API to do this? It sure would be great to get rid of one of several backup solutions we have in place!”

What we showed in Barcelona and on several blogs is how to back up the VCSA through the Appliance UI, clicking the ‘Backup button’. So I wanted to take a chance to answer Rob’s question here, which will benefit all of you as well.

Pre-reqs

The short answer is YES, we do have an API that can be used, and I have a script below that you can use to do just that! Before we start, there are a few things you need to have in place:

  • VCSA backup can be backed up to either:
    • FTP
    • FTPS
    • HTTP
    • HTTPS
    • SCP
  • Make sure that you have valid user credentials as well as write/create folder/read permissions for the target
  • Know the location of the target

Now, I can’t take full credit for this, as Alan Renouf (twitter: @alanrenouf) started the Backup-VCSAToFile function, which he shared with me. I took his function he created and made it more robust and added in additional checks, progress visibility, and parameters. So Thanks Alan for getting this first function started for us!

Using this module

Backup-VCSAToFile

Grab this module from the VMware PowerCLI GitHub repo. You’ll notice there are three functions:

  • Backup-VCSAToFile
  • Get-VCSABackupJobs
  • Get-VCSABackupStatus

The first is what you’ll use to create your VCSA Backups. The others are more for monitoring afterwards.

There are a few parameters you need to set:

  • FullBackup/SeatBackup (These are switches. You must choose one)
  • LocationType (This is where you input whether this is FTP, FTPS, etc. You can tab through the options)
  • Location (This will be the location in the locationtype where your backup will be stored)
  • LocationUser (User for the location type)
  • LocationPassword (User’s password)
  • BackupPassword (If you choose to encrypt the backup, this is the encryption password)
  • Comment (Additional comments for the specific backup)
  • ShowProgress (switch to see the progress of the backup)

 

When working on this function, I just saved all the required variables like this:

[VMware.VimAutomation.Cis.Core.Types.V1.Secret]$BackupPassword = “VMw@re123”
$Comment = “First API Backup”
$LocationType = “FTP”
$location = “10.144.99.5/vcsabackup-$((Get-Date).ToString(‘yyyy-MM-dd-hh-mm’))”
$LocationUser = “admin”
[VMware.VimAutomation.Cis.Core.Types.V1.Secret]$locationPassword = “VMw@re123”

and then used the variables in the function to start the backup (you will notice that the passwords need to be a specific type (Cis.Core.Types.V1.Secret) if you type a plaintext password as a parameter, the function will automatically save it as this type.

Kicking off the script then looks like this (for me)

Backup-VCSAToFile -BackupPassword $BackupPassword  -LocationType $LocationType -Location $location -LocationUser $LocationUser -LocationPassword $locationPassword -Comment “This is a demo” -ShowProgress -FullBackup

vcsabackup

You will see the progress (if you set the ShowProgress switch) all the way until it completes, or if you have some sort of failure due to the input parameters.

Get-VCSABackupJobs

You can retrieve a list of all backups a VCSA has run (note*: This doesn’t mean that all of them still exist in the backup location).

You’ll see that the backup ID actually is quite smart:

Running the function below returns all the backups.

As you’ll see from the screenshot, the backup ID’s are actually YYYYMMDD-hhmmss-VcsaBuildNumber

Now, just so you are aware, the hhmmss is based on the timezone you set in the VCSA appliance management page, so if you left it at UTC you will need to realize that the time is not showing your local time.

backupjobs

Ok, so seeing all these is kinda cool, but how useful is this really? That is where the final function comes in handy.

Get-VCSABackupStatus

Running this function by itself will not return any data, however, using a backup ID from the previous function will bring back info about that backup job. The great thing about this function is it allows objects from the pipeline meaning you can run the previous function and pipe it to this function

Now, this will return potentially a lot of data. However, you can do something such as one of these examples:

backup-status

All in all, these should help you automate your backups as well as see the progress or final result of each. Let me know how you like it either on Twitter (@vBrianGraf) or in the comment section below!

You can find this on VMware’s Github repo HERE

 

 

1 comment

  1. Jeff White

    I am new to PowerShell. My vCenter does not seem to connect with connect-cisservice. I have always used connect-viserver. I have tried both vCenter and the Appliance credentials.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

four × three =