Restore a
vCenter Server
Instance by Using the API

You can use the
of to restore a
vCenter Server
instance from a backup file containing the
vCenter Server
database and key components of the
vCenter Server
instance.
  • Verify that the backed up
    vCenter Server
    instance is powered off.
  • A new
    vCenter Server
    instance must be deployed in an unconfigured state, except that it must have a fully qualified domain name or IP address that matches the old one.
  • Verify that the new
    vCenter Server
    instance has the same build number as the one in the backup file.
  • Verify that the new
    vCenter Server
    instance has a size equal to or greater than the old one. If the old
    vCenter Server
    instance was customized to exceed the largest template size, the new one must be customized to the same size.
  • Verify that no other backup or restore jobs are running.
  • Verify that the destination storage location is accessible to the
    vCenter Server
    restore process.
  1. Create a restore request object
    to describe the restore operation.
  2. Issue a request to start the restore operation.
  3. Monitor the progress of the job until it is complete.
  4. Report job completion.
After the
vCenter Server
instance is fully configured by the restore operation, you can resume using the
vSphere Automation
API endpoint for subsequent operations.
Python
This example shows how to use Python to restore a
vCenter Server
instance. This operation is the second phase of restoring the
vCenter Server
instance from a backup image.
This example uses the following global variables.
  • my_vcsa_hostname
  • my_vcsa_username
  • my_vcsa_password
  • my_backup_name
  • my_storage_server
  • my_scp_user
  • my_scp_password
  • my_backup_folder
When you restore the
vCenter Server
instance from a backup image, you need two sets of authentication credentials. The API client needs to authenticate to the
vCenter Server
instance, and the
vCenter Server
backup service needs to authenticate to the backup storage server.
The example uses local user name and password authentication for the connection to the
vCenter Server
instance because the
vSphere Automation
API endpoint is not yet running when you restore the
vCenter Server
instance. The client must connect to port
5480
for this operation.
In the restore request, you need to specify the folder that contains the backup image. The folder name is the same name that was specified in the backup request. It must be specified as a path name relative to the home directory of the user that authenticates with the storage server.
This example assumes the backup image is not encrypted.
import requests from vmware.vapi.lib.connect import get_requests_connector from vmware.vapi.security.user_password import create_user_password_security_context from vmware.vapi.stdlib.client.factories import StubConfigurationFactory from com.vmware.appliance.recovery.restore_client import (Job) import time # Create a session object in the client. session = requests.Session() # For development environment only, suppress server certificate checking. session.verify = False from requests.packages.urllib3 import disable_warnings from requests.packages.urllib3.exceptions import InsecureRequestWarning disable_warnings(InsecureRequestWarning) # Create a connection to port 5480. local_url = 'https://%s:5480/api' % my_vcsa_hostname connector = get_requests_connector(session=session, url=local_url) # Add username/password security context to the connector. basic_context = create_user_password_security_context(my_vcsa_username, my_vcsa_password) connector.set_security_context(basic_context) # Create a stub configuration by using the username-password security context. local_stub_config = StubConfigurationFactory.new_std_configuration(connector) # Create a restore request object. req = Job.RestoreRequest() req.location_type = Job.LocationType.SCP req.location = my_storage_server + ':/home/scpuser/' + my_backup_folder + '/' + my_backup_name req.location_user = my_scp_user req.location_password = my_scp_password # Issue a request to start the restore operation. restore_job = Job( local_stub_config ) job_status = restore_job.create( req ) # Monitor progress of the job until it is complete. while (job_status.state == Job.BackupRestoreProcessState.INPROGRESS) : print( 'Restore job state: {} ({}%)'.format( job_status.state, job_status.progress ) ) time.sleep( 10 ) job_status = restore_job.get() # Report job completion. print( 'Restore job completion status: {}'.format( job_status.state) )