Skip to content

Commit df3aa18

Browse files
Take stu_name as input paramer and corrected typos
1 parent ba583e8 commit df3aa18

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

recipes/python/backup-restore/README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# NetBackup VmWare agentless single and group VM backup and restore APIs code samples
1+
# NetBackup VMware agentless single and group VM backup and restore APIs code samples
22

33
## Executing the scripts:
44

55
Pre-requisites:
66
- NetBackup 8.3 or higher
77
- Python 3.6 or higher
88
- Python modules: `requests`
9+
- create_protection_plan_template.json template file. This template contain the required payload which is used to create the protection plan.
910

1011
Use the following commands to run the scripts.
1112
### - Single VM backup and restore
1213

13-
This single_vm_backup_restore.py script demonstrates how to backup a VM (VMware virtual machine) using a protection plan and restore it using NetBackup APIs.
14+
This single_vm_backup_restore.py script demonstrates how to backup a VM (VMware virtual machine) using a protection plan and instant access restore of VM using NetBackup APIs.
1415

15-
`python single_vm_backup_restore.py --master_server <master_server> --master_username <master_username> --master_password <master_password> --vcenter_name <vcenter_name> --vcenter_username <vcenter_username> --vcenter_password <vcenter_password> --protection_plan_name <protection_plan_name> --clientvm <client_vm_name> --restore_vmname <restore_vm_name>`
16+
`python single_vm_backup_restore.py --master_server <master_server> --master_username <master_username> --master_password <master_password> --vcenter_name <vcenter_name> --vcenter_username <vcenter_username> --vcenter_password <vcenter_password> --stu_name <stu_name> --protection_plan_name <protection_plan_name> --clientvm <client_vm_name> --restore_vmname <restore_vm_name>`
1617

1718
All parameters can also be passed as command line arguments.
1819
- `python single_vm_backup_restore.py --help`
@@ -25,6 +26,7 @@ usage: single_vm_backup_restore.py [-h] [--master_server MASTER_SERVER]
2526
[--vcenter_username VCENTER_USERNAME]
2627
[--vcenter_password VCENTER_PASSWORD]
2728
[--vcenter_port VCENTER_PORT]
29+
[--stu_name STU_NAME]
2830
[--protection_plan_name PROTECTION_PLAN_NAME]
2931
[--clientvm CLIENTVM]
3032
[--restore_vmname RESTORE_VMNAME]
@@ -42,13 +44,15 @@ Arguments:
4244
--master_password MASTER_PASSWORD
4345
NetBackup master server password
4446
--vcenter_name VCENTER_NAME
45-
Vcenter name
47+
vCenter name
4648
--vcenter_username VCENTER_USERNAME
47-
Vcenter username
49+
vCenter username
4850
--vcenter_password VCENTER_PASSWORD
49-
Vcenter password
51+
vCenter password
5052
--vcenter_port VCENTER_PORT
51-
Vcenter port
53+
vCenter port
54+
--stu_name STU_NAME
55+
Storage unit name
5256
--protection_plan_name PROTECTION_PLAN_NAME
5357
Protection plan name
5458
--clientvm CLIENTVM Client VM name
@@ -69,9 +73,9 @@ Execution flow of single VM backup and restore script:
6973

7074
### - Group VM backup and restore
7175

72-
This group_vm_backup_restore.py script demonstrates how to backup multiple VMs (VMware virtual machines) using a protection plan and perform bulk restore of the VMs using NetBackup APIs.
76+
This group_vm_backup_restore.py script demonstrates how to backup multiple VMs (VMware virtual machines) using a protection plan and perform bulk instant access restore of the VMs using NetBackup APIs.
7377

74-
`python group_vm_backup_restore.py --master_server <master_server> --master_username <master_username> --master_password <master_password> --vcenter_name <vcenter_name> --vcenter_username <vcenter_username> --vcenter_password <vcenter_password> --protection_plan_name <protection_plan_name> --querystring <Query_string> --vip_group_name <group_name> --restore_vmname_prefix <restore_vmname_prefix>`
78+
`python group_vm_backup_restore.py --master_server <master_server> --master_username <master_username> --master_password <master_password> --vcenter_name <vcenter_name> --vcenter_username <vcenter_username> --vcenter_password <vcenter_password> --stu_name <stu_name> --protection_plan_name <protection_plan_name> --querystring <Query_string> --vip_group_name <group_name> --restore_vmname_prefix <restore_vmname_prefix>`
7579

7680
All parameters can also be passed as command line arguments.
7781
- `python group_vm_backup_restore.py --help`
@@ -84,6 +88,7 @@ usage: group_vm_backup_restore.py [-h] [--master_server MASTER_SERVER]
8488
[--vcenter_username VCENTER_USERNAME]
8589
[--vcenter_password VCENTER_PASSWORD]
8690
[--vcenter_port VCENTER_PORT]
91+
[--stu_name STU_NAME]
8792
[--protection_plan_name PROTECTION_PLAN_NAME]
8893
[--querystring QUERYSTRING]
8994
[--vip_group_name VIP_GROUP_NAME]
@@ -109,6 +114,8 @@ Arguments:
109114
Vcenter password
110115
--vcenter_port VCENTER_PORT
111116
Vcenter port
117+
--stu_name STU_NAME
118+
Storage unit name
112119
--protection_plan_name PROTECTION_PLAN_NAME
113120
Protection plan name
114121
--querystring QUERYSTRING

recipes/python/backup-restore/common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,20 @@ def get_asset_info(baseurl, token, workload_type, client):
8888
print(f"Client exsi host:[{exsi_host}]")
8989
return asset_id, uuid, exsi_host
9090

91-
# Get StorageUnits
92-
def get_storage_units(baseurl, token):
93-
""" This function return the storage unit name """
91+
# Verify the storage unit is supported for instant access
92+
def verify_stu_instant_access_enable(baseurl, token, storage_unit_name):
93+
""" Verify the storage unit is supported for instant access """
9494
headers.update({'Authorization': token})
95-
url = f"{baseurl}storage/storage-units"
95+
url = f"{baseurl}storage/storage-units/?filter=name eq '{storage_unit_name}'"
9696
status_code, response_text = rest_request('GET', url, headers)
9797
validate_response(status_code, 200, response_text)
98-
storage_unit_name = response_text['data'][0]['id']
9998
is_instant_access_enable = response_text['data'][0]['attributes']['instantAccessEnabled']
10099

101100
if is_instant_access_enable:
102101
print(f"Storage unit:[{storage_unit_name}] enabled for instant access")
103102
else:
104103
print(f"Storage unit:[{storage_unit_name}] disable for instant access")
105104
raise Exception(f"Storage unit:[{storage_unit_name}] disabled for instant access")
106-
return storage_unit_name
107105

108106
# Create protection plan
109107
def create_protection_plan(baseurl, token, protection_plan_name, storage_unit_name):

recipes/python/backup-restore/group_vm_backup_restore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PARSER.add_argument("--vcenter_username", type=str, help="Vcenter username")
1919
PARSER.add_argument("--vcenter_password", type=str, help="Vcenter password")
2020
PARSER.add_argument("--vcenter_port", type=str, help="Vcenter port", required=False)
21+
PARSER.add_argument("--stu_name", type=str, help="Storage Unit name")
2122
PARSER.add_argument("--protection_plan_name", type=str, help="Protection plan name")
2223
PARSER.add_argument("--querystring", type=str, help="Query string to create the VM intelligent group")
2324
PARSER.add_argument("--vip_group_name", type=str, help="VM intelligent group name")
@@ -159,8 +160,8 @@ def remove_vm_intelligent_group(baseurl, token, vm_group_id):
159160
print(f"Setup the VMware environment for vCenter:[{ARGS.vcenter_name}]")
160161
common.add_vcenter_credential(BASEURL, TOKEN, ARGS.vcenter_name, ARGS.vcenter_username, ARGS.vcenter_password, ARGS.vcenter_port, SERVER_TYPE)
161162
common.verify_vmware_discovery_status(BASEURL, TOKEN, WORKLOAD_TYPE, ARGS.vcenter_name)
162-
STORAGE_UNIT_NAME = common.get_storage_units(BASEURL, TOKEN)
163-
PROTECTION_PLAN_ID = common.create_protection_plan(BASEURL, TOKEN, ARGS.protection_plan_name, STORAGE_UNIT_NAME)
163+
common.verify_stu_instant_access_enable(BASEURL, TOKEN, ARGS.stu_name)
164+
PROTECTION_PLAN_ID = common.create_protection_plan(BASEURL, TOKEN, ARGS.protection_plan_name, ARGS.stu_name)
164165

165166
print("Create intelligent VM group and take backup")
166167
create_vm_intelligent_group(BASEURL, TOKEN, ARGS.vip_group_name, ARGS.querystring, ARGS.vcenter_name)

recipes/python/backup-restore/single_vm_backup_restore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
PARSER.add_argument("--vcenter_username", type=str, help="Vcenter username")
2020
PARSER.add_argument("--vcenter_password", type=str, help="Vcenter password")
2121
PARSER.add_argument("--vcenter_port", type=str, help="Vcenter port", required=False)
22+
PARSER.add_argument("--stu_name", type=str, help="Storage Unit name")
2223
PARSER.add_argument("--protection_plan_name", type=str, help="Protection plan name")
2324
PARSER.add_argument("--clientvm", type=str, help="Client VM name")
2425
PARSER.add_argument("--restore_vmname", type=str, help="Restore VM name")
@@ -40,9 +41,9 @@
4041
print(f"Setup the VMware environment for vCenter:[{ARGS.vcenter_name}]")
4142
common.add_vcenter_credential(BASEURL, TOKEN, ARGS.vcenter_name, ARGS.vcenter_username, ARGS.vcenter_password, ARGS.vcenter_port, SERVER_TYPE)
4243
common.verify_vmware_discovery_status(BASEURL, TOKEN, WORKLOAD_TYPE, ARGS.vcenter_name)
43-
STORAGE_UNIT_NAME = common.get_storage_units(BASEURL, TOKEN)
44+
common.verify_stu_instant_access_enable(BASEURL, TOKEN, ARGS.stu_name)
4445
ASSET_ID, _, EXSI_HOST = common.get_asset_info(BASEURL, TOKEN, WORKLOAD_TYPE, ARGS.clientvm)
45-
PROTECTION_PLAN_ID = common.create_protection_plan(BASEURL, TOKEN, ARGS.protection_plan_name, STORAGE_UNIT_NAME)
46+
PROTECTION_PLAN_ID = common.create_protection_plan(BASEURL, TOKEN, ARGS.protection_plan_name, ARGS.stu_name)
4647
SUBSCRIPTION_ID = common.subscription_asset_to_slo(BASEURL, TOKEN, PROTECTION_PLAN_ID, ASSET_ID)
4748

4849
# Single VM backup and restore

0 commit comments

Comments
 (0)