-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_latest_catalog_snapshot.py
54 lines (42 loc) · 1.6 KB
/
restore_latest_catalog_snapshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
""" This scenario restores latest catalog snapshot
Scenario requires below Environment Variables:
APPLIANCE_ADMIN_USERNAME=""
APPLIANCE_ADMIN_PASSWORD=""
API_GATEWAY_IP=""
"""
import logging
import os
import sys
import utils
import log
sys.path.append(os.path.realpath('..'))
logger = logging.getLogger('restore_latest_catalog_snapshot')
logger.addHandler(logging.NullHandler())
log.init_logger()
def main():
username = os.environ["APPLIANCE_ADMIN_USERNAME"]
passwd = os.environ["APPLIANCE_ADMIN_PASSWORD"]
api_gateway = os.environ["API_GATEWAY_IP"]
# Input parameter validation
if(not username or not passwd or not api_gateway):
logger.error("Missing required environment variable/s,"
"please check doc string for required variables")
return 1
# Description: Get catalog Snapshots
response = utils.run_api(api_gateway,
"/api/appliance/v1.0/netbackup/checkpoints",
username, passwd, req_type="get")
# Get latest snapshot
latest_snapshot = response["data"][0]["links"]["self"]["href"].split("/")[-1]
# Validate latest catalog snapshot
utils.run_api(api_gateway,
"/api/appliance/v1.0/netbackup/checkpoints/restore"
"-catalog/{}".format(latest_snapshot), username,
passwd, req_type="post")
# Restore latest catalog snapshot
utils.run_api(api_gateway,
"/api/appliance/v1.0/netbackup/checkpoints/"
"sync-catalog", username,
passwd, req_type="post")
if __name__ == "__main__":
main()