Loading...

Samples for the Developer SDK for Python

The following compressed file contains samples for the Python SDK: Samples_for_Python.zip. The following samples are inside the compressed file and can be modified to meet a specific need.

Authentication

The Commcell_login.py script runs CommCell log on and log off operations.

>>> from cvpysdk.commcell import Commcell
>>>
>>> commcell = Commcell('test.idcprodcert.loc', 'admin', '**********')
>>>
>>>
>>> commcell = Commcell('test.idcprodcert.loc', 'admin')
Please enter the Commcell Password: **********
>>>
>>> commcell.logout()
'User logged out'
>>>

Editing Subclient Properties

The Sub_props.py script updates subclient properties.

>>> from cvpysdk.commcell import Commcell
>>> commcell = Commcell('test.idcprodcert.loc', 'admin', 'password123')
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')
>>>
>>> print(subclient.storage_policy)
test_policy
>>>
>>> subclient.storage_policy = 'vs_sdk_test_policy'
>>>
>>> print(subclient.storage_policy)
vs_sdk_test_policy
>>>
>>>
>>> print(subclient.content)
['C:\\inetpub', 'C:\\ProgramData', 'C:\\Python27', 'C:\\restore_test']
>>>
>>> subclient.content = ['C:\\inetpub', 'C:\\Python27', 'C:\\restore_test']
>>>
>>> print(subclient.content)
['C:\\inetpub', 'C:\\Python27', 'C:\\restore_test']
>>>
>>>
>>> print(subclient.description)

>>> subclient.description = 'Test Subclient for Python SDK'
>>>
>>> print(subclient.description)
Test Subclient for Python SDK
>>>
>>> commcell.logout()
'User logged out'
>>>

Polling the Job Status

The Job.py script runs job operations.

>>> from cvpysdk.commcell import Commcell
>>> commcell = Commcell('test.idcprodcert.loc', 'admin', 'password123')
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')
>>>
>>> job = subclient.backup('Full')
>>>
>>> print(job.status)
Running
>>>
>>> job.pause()
>>>
>>> print(job.status)
Suspend Pending
>>>
>>> print(job.status)
Suspended
>>>
>>>
>>> print(job.pending_reason)
Backup job has been suspended by user admin. Reason:[].<br>Source: test, Process: JobManager
>>>
>>> print(job.delay_reason)
Backup job has been suspended by user admin. Reason:[].<br>Source: test, Process: JobManager
>>>
>>>
>>> print(job.backup_level)
Full
>>>
>>> job.finished
False
>>>
>>> print(job.job_type)
Backup
>>>
>>> print(job.job_id)
745
>>>
>>> job.resume()
>>>
>>> print(job.status)
Running
>>>
>>> job.kill()
>>>
>>> print(job.status)
Completed w/ one or more errors
>>>
>>> print(job.start_time)
Thu Apr 13 12:24:37 2017
>>>
>>> print(job.end_time)
Thu Apr 13 12:28:38 2017
>>>

Running Cloud Apps Backup and Restore

The Ca_bkp_rst.py script runs backup, browse, and restore operations on a Cloud Apps agent subclient.

>>> from cvpysdk.commcell import Commcell
>>> commcell = Commcell('test.idcprodcert.loc', 'admin', '**********')
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('Cloud Apps')
>>> instance = agent.instances.get('GMail-Instance')
>>> subclient = instance.subclients.get('test_sub')
>>>
>>> job = subclient.backup()
>>>
>>> print(job.status)
Running
>>>
>>> print(job.status)
Completed
>>>
>>>
>>> paths, details_dict = subclient.browse()
>>>
>>> print(paths)
['\\Gmail']
>>>
>>> print(details_dict)
{'\\Gmail': ['Gmail', 'Folder', '0B', '01/01/1970 05:30:00']}
>>>
>>>
>>> paths, details_dict = subclient.browse(paths[0])
>>>
>>> print(paths)
['\\Gmail\\jdoe@commvaultga.com']
>>>
>>> print(details_dict)
{'\\Gmail\\jdoe@commvaultga.com': ['jdoe@commvaultga.com', 'Folder', '0B', '01/01/1970 05:30:00']}
>>>
>>>
>>> job = subclient.restore_out_of_place('test', 'jdoe@commvaultga.com/automation', ['\\Gmail\\jdoe@commvaultga.com\\INBOX'])
>>>
>>> print(job.status)
Running
>>>
>>> print(job.status)
Completed
>>>
>>> commcell.logout()
'User logged out'
>>>

Running File System Backup and Restore

The Fs_bkp_brws_rest.py script runs backup, browse, and restore operations on a File System agent subclient.

>>> from cvpysdk.commcell import Commcell
>>> commcell = Commcell('test.idcprodcert.loc', 'admin', '**********')
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')
>>>
>>> job = subclient.backup()
>>>
>>> print(job.status)
Running
>>>
>>> print(job.status)
Completed
>>>
>>>
>>> paths, details_dict = subclient.browse()
>>>
>>> print(paths)
['C:']
>>>
>>> print(details_dict)
{'C:': ['C:', 'Folder', '980.68 MB', '10/04/2017 12:28:37']}
>>>
>>>
>>> paths, details_dict = subclient.browse(paths[0])
>>>
>>> print(paths)
['C:\\inetpub', 'C:\\ProgramData', 'C:\\Python27', 'C:\\restore_test']
>>>
>>> job = subclient.restore_out_of_place('test', 'C:\\sdk_restore', ['C:\\inetpub', 'C;\\restore_test'])
>>>
>>> print(job.status)
Running
>>>
>>> print(job.status)
Completed
>>>
>>> commcell.logout()
'User logged out'
>>>

Associating a Plan with an Entity

The plan_assoc_entity.py script associates a plan with an entity.

>>> from cvpysdk import commcell
>>> commcell = commcell.Commcell("test.xyz.com", "admin", "******")
>>> test_plan = commcell.plans.get("test_plan_name")
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')

>>> # Associates a plan to a backupset
…backupset.plan = test_plan

>>> # Associates a plan to a subclient
…subclient.plan = test_plan

Schedule Policies

The sch_pol.py script returns a list of schedule policies, a schedule object that is going to change, adds schedule policies associated with a subclient, and removes schedule policies associated with a subclient.

>>>from cvpysdk.commcell import Commcell

>>>from cvpysdk.policies.schedule_policies import OperationType

>>>commcellobj = Commcell('test.idcprodcert.loc', 'admin', '******')

>>>print(commcellobj.schedule_policies) #Returns all the schedule policies in the CommCell

>>>sch_pol_obj = commcellobj.schedule_policies.get('testsch1') #Returns a schedule object that is going to change

>>>associations = [{'clientName': 'test', 'instanceName': "DefaultInstanceName", 'appName':"File System",
'backupsetName':"defaultBackupSet" , 'subclientName': "test_sub"}]

>>>sch_pol_obj.update_associations(associations, OperationType.DELETE) #Removes schedule policies associated with a subclient

>>>associations = [{'clientName': 'test', 'instanceName': "DefaultInstanceName", 'appName':"File System",
'backupsetName':"defaultBackupSet" , 'subclientName': "test_sub"}]

>>>sch_pol_obj.update_associations(associations, OperationType.INCLUDE)#Adds schedule policies associated with a subclient

Disassociating a Plan from an Entity

The plan_disassoc_entity.py script disassociates a plan from an entity.

>>> from cvpysdk import commcell
>>> commcell = commcell.Commcell("test.xyz.com", "admin", "******")
>>> test_plan = commcell.plans.get("test_plan_name")
>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')

>>> # Dissociates any plan if associated with the backupset
…backupset.plan = None

>>> # Dissociates any plan if associated with the subclient
…subclient.plan = None

Viewing Entity Associations for a Plan

The plan_entities.py script returns a list of entities associated with a plan and a list of plans associated with an entity.

>>> from cvpysdk import commcell
>>> commcell = commcell.Commcell("test.xyz.com", "admin", "******")
>>> test_plan = commcell.plans.get("test_plan_name")

>>> # Returns list of entities associated with test_plan
…print(test_plan. associated_entities)
[{'subclientId': 1862, 'applicationId': 33, 'clientName': 'name_of_client, 'displayName': ''name_of_client', 'backupsetId': 1847, 'instanceId': 1, 'clientId': 2, 'subclientName': 'subclient_name1', 'backupsetName': '443', 'instanceName': 'DefaultInstanceName', '_type_': 7, 'appName': 'Windows File System'}, {'subclientId': 219, 'applicationId': 33, 'clientName': ' name_of_client ', 'displayName': 'name_of_client', 'backupsetId': 212, 'instanceId': 1, 'clientId': 20, 'subclientName': 'default', 'backupsetName': 'defaultBackupSet', 'instanceName': 'DefaultInstanceName', '_type_': 7, 'appName': 'Windows File System'}]

>>> client = commcell.clients.get('test')
>>> agent = client.agents.get('File System')
>>> backupset = agent.backupsets.get('defaultBackupSet')
>>> subclient = backupset.subclients.get('test_sub')

>>> # Returns the plan associated with the backupset
…print(backupset.plan)
'test_plan_name'

>>> # Returns the plan associated with the subclient
…print(subclient.plan)
'test_plan_name'

Last modified: 5/18/2020 2:09:48 PM