VMware Cloud Community
Travis_83
Enthusiast
Enthusiast
Jump to solution

vSphere 6.5 – Automate VCSA Backup (Lost)

Hi guys,

Hoping you can help a CLI noob.

I'm trying to get this to work as per Brian's article (https://www.brianjgraf.com/2016/11/18/vsphere-6-5-automate-vcsa-backup) and failing hopelessly.

I'm just confused as to how to execute this script and I'm not sure if I'm missing something critical to make it work. I'm a little confused by Brian's mention of the function/variables.

Does he include them in the script (at the beginning, under Function Backup-VCSAToFile { ?) and if so, where the 'ell do they go. When I try execute the script as seen below and in Brian's screenshot:

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

I get a message saying - Suggestion [3,General]: The command Backup-VCSAToFile was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Backup-VCSAToFile". See "get-help about_Command_Precedence" for more details.

If I add the ./******.ps1 and execute, it does nothing.

Where am I going wrong here - I have a feeling I need to load the modules (or something) otherwise how does it recognise Backup-VCSAToFile

Please help!

Kind Regards,

Travis

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you want to reuse this, a script would be better (a .ps1 file).

In the file put something like this

  1. Load the module
  2. Set the variables (adapt for your evnvironment)
  3. Call the backup cmdlet from Brian's modul

Import-Module .\Backup-VCSA.psm1

[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”

Backup-VCSAToFile -BackupPassword $BackupPassword  -LocationType $LocationType `

    -Location $location -LocationUser $LocationUser `

    -LocationPassword $locationPassword -Comment $Comment -ShowProgress -FullBackup


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

15 Replies
LucD
Leadership
Leadership
Jump to solution

Brian packaged his functions as a module.

When you download his module file (Backup-VCSA.psm1), don't forget to Unblock the file, you can do the following:

  • import the module (you might have to adapt the path, depending where you saved the file)

Import-Module .\Backup-VCSA.psm1

  • call the functions to do the VCSA backup


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Travis_83
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

I actually tried that yesterday and thought I had cracked it. I tried a few things and it came up with null expression errors.

What I'm really confused about is how to run the custom variables that Brian mentions in his article, specifying the location etc.

How am I running this - in CLi or do I incorporate it in the script.

If someone could clarify that bit.

Thanks,

Travis

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want to reuse this, a script would be better (a .ps1 file).

In the file put something like this

  1. Load the module
  2. Set the variables (adapt for your evnvironment)
  3. Call the backup cmdlet from Brian's modul

Import-Module .\Backup-VCSA.psm1

[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”

Backup-VCSAToFile -BackupPassword $BackupPassword  -LocationType $LocationType `

    -Location $location -LocationUser $LocationUser `

    -LocationPassword $locationPassword -Comment $Comment -ShowProgress -FullBackup


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Travis_83
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Is it possible to automate this script - would task scheduler be the best option?

If so, how would I call this particular script as a task in task scheduler.

thanks,

travis

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, the Windows Task Scheduler on a Windows box would be good.

See How To Automatically Run PowerShell Scripts at a Scheduled Time on how to set it up.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

multihawk
Contributor
Contributor
Jump to solution

If I have multiple VCSA and PSC to backup how do I tell this all of those names in one script instead of setting up multiple scheduled tasks?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you store all the information in for example a CSV file?

If yes, then you could in a loop (row by row), run the backup for each VCSA


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
multihawk
Contributor
Contributor
Jump to solution

I can do that. Guessing I can utilize our current script that lists them all and then loops through them for other items.  We do have a locked-down dedicated util server for just Virt Operations because we have so many VCSA.

Thanks.

Reply
0 Kudos
Travis_83
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

We had some new appliances deployed in our environment, but since the success of my previous back-ups I have been unable to get these new ones to work and I don't understand why.

Nothing is different so I assumed the scripts would just work as they do for the others.

I'm getting errors like:

A server error occurred: 'com.vmware.vapi.std.errors.unauthorized': Unable to authorize user (Server error id:

'vapi.security.authorization.invalid'). Check $Error[0].Exception.ServerError for more details.

At C:\VCSA\Backup-VCSA.psm1:76 char:13

+             throw $_.Exception.Message

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (A server error ...r more details.:String) [], RuntimeException

    + FullyQualifiedErrorId : A server error occurred: 'com.vmware.vapi.std.errors.unauthorized': Unable to authori

   ze user (Server error id: 'vapi.security.authorization.invalid'). Check $Error[0].Exception.ServerError for mor

  e details.

---------------------------------------------------------------------------------------------------------------------------------------------------------------

The property 'parts' cannot be found on this object. Verify that the property exists and can be set.

At C:\VCSA\Backup-VCSA.psm1:65 char:9

+         $CreateSpec.parts = $parts

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyAssignmentException

The property 'backup_password' cannot be found on this object. Verify that the property exists and can be set.

At C:\VCSA\Backup-VCSA.psm1:66 char:9

+         $CreateSpec.backup_password = $BackupPassword

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyAssignmentException

<Continues>

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

I've done back-ups manually to confirm the FTP information I'm using is correct by connecting to the appliance via the web console. I've connected to the appliance via SSH to check services are all running. I'm using the administrator@vsphere.local accounts to authenticate as I did for the others, this appears to have all the rights necessary.

I'm pretty stumped to be honest.

Do you know where I can look to better understand where the problem lies i.e. logs etc.

Kind Regards,

Travis

Reply
0 Kudos
multihawk
Contributor
Contributor
Jump to solution

Have a look at vcsa 6.5 trying to automate the backup - authentication failure  as I was having issues with the services as well and was able to get it to work with a couple restarts of them.

Travis_83
Enthusiast
Enthusiast
Jump to solution

thank you, that happened to be my issue, a few restarts of the endpoint service, eventually played ball. thanks again.

Travis_83
Enthusiast
Enthusiast
Jump to solution

Hi guys,

Does anyone have an updated version of the script or variant because I can't get this to work anymore or at least consistently (I think my issue is with PowerCLi/PS versions, and since appliances and VMWare system has been upgraded.

kind regards,

travis

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you getting any kind of error when it fails?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
kaartik
Contributor
Contributor
Jump to solution

When running the script, we are getting this error -

The property parts cannot be sound on this object. Verify that the property exists and can be set.

This shows up for all properties associated with $CreateSpec

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Does your authentication work to the CIS server?

And when it does, does the following return 'common' and 'seat'?

You'll have to update the user/password values.

Connect-CisServer -Server <vcsa-fqdn> -User administrator@vsphere.local -Password VMware1!

$cis = Get-CisService -Name 'com.vmware.appliance.recovery.backup.parts'

$cis.list().id

Disconnect-CisServer -Server <vcsa-fqdn> -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos