Back up a
vCenter Server
Instance by Using the API
Last Updated December 16, 2024

You can use the
to create a backup of the
vCenter Server
database and key components of the
vCenter Server
instance.
  • Verify that the
    vCenter Server
    instance is in a ready state. All processes with start-up type
    automatic
    must be running.
  • Verify that no other backup or restore jobs are running.
  • Verify that the destination storage location is accessible to the backup process.
  • Verify that the path to the destination directory exists, as far as the parent directory.
  • If the destination directory does not exist, the backup process creates it. If the directory does exist, verify that it is empty.
  • Verify that the destination storage device has sufficient space for the backup file. For information about how to calculate the space needed for the backup file, see Calculate the Size Needed To Store the Backup File.
This procedure explains the sequence of operations you use to create a backup file of the
vCenter Server
instance. You can do this as part of a regular maintenance schedule.
  1. Authenticate to the
    vSphere Automation
    API endpoint and establish a session.
  2. Create a backup request object
    to describe the backup operation.
    The
    request
    specifies several
    attributes
    , especially the backup location, the protocol used to communicate with the storage server, the necessary authorization, and which optional parts of the database you want to back up. The core inventory data and Alarms are always backed up, but you can choose whether or not to back up Statistics, Events, and Tasks. Collectively, this optional part of the backup is referred to as
    seat
    .
  3. Issue a request to start the backup operation.
  4. From the response, save the unique job identifier of the backup operation.
  5. Monitor the progress of the job until it is complete.
  6. Report job completion.
The backup file of the
vCenter Server
instance is created.
Python
This example specifies that the backup image should include Statistics, Events, and Tasks as well as the core inventory and alarm data. The value for
req.parts
indicates the optional data part for Statistics, Events, and Tasks.
This example uses the following global variables.
  • my_storage_server
  • my_backup_folder
  • my_scp_user
  • my_scp_password
  • my_stub_config
When you back up the
vCenter Server
instance, you need two sets of authentication credentials. The API client needs to authenticate to the
vCenter Server
instance, and the backup service needs to authenticate to the backup storage server.
The example assumes that your API client has already authenticated the connection to the
vCenter Server
instance, and the security context is stored in
my_stub_config
.
In the backup request, you need to specify the folder that will contain the backup image. The folder name must be specified as a path name relative to the home directory of the user that authenticates with the storage server.
from com.vmware.appliance.recovery.backup_client import Job
import time

# This example assumes you have previously created a session
# and stored the session ID in my_stub_config.

# Create a backup request object.
req = Job.BackupRequest()
# Include optional backup part for Statistics, Events, and Tasks.
req.parts = ['seat']
req.location_type = Job.LocationType.SCP
req.comment = 'On-demand backup'
req.location = my_storage_server + ':/home/scpuser/' + my_backup_folder \
  + '/' + time.strftime('%Y-%m-%d-%H-%M-%S')
req.location_user = my_scp_user
req.location_password = my_scp_password

# Issue a request to start the backup operation.
backup_job = Job( my_stub_config )
job_status = backup_job.create( req )
job_id = job_status.id

# Monitor progress of the job until it is complete.
while (job_status.state == Job.BackupRestoreProcessState.INPROGRESS) :
    print( 'Backup job state: {} ({}%)'.format( job_status.state, \
                                                 job_status.progress ) )
    time.sleep( 10 )
    job_status = backup_job.get( job_id )

# Report job completion.
print( 'Backup job completion status: {}'.format( job_status.state) )