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'
>>>

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'
>>>

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'
>>>

Last modified: 3/8/2018 8:03:22 PM