Skip to content

Commit efd64f6

Browse files
Merge pull request #10 from VeritasOS/feature/curl_samples
Curl samples for listing nb jobs and backup images
2 parents 89b76a2 + dfe743b commit efd64f6

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ Pre-requisites:
2929
- NetBackup 8.1.1 or higher
3030
- See script README for perl requirements and usage
3131

32+
#### Executing the snippets using curl
33+
Pre-requisites:
34+
- NetBackup 8.1.1 or higher
35+
- curl 7.51.0 or higher
36+
- jq command-line parser (https://github.com/stedolan/jq/releases)
37+
38+
Use the following commands to run the curl samples.
39+
- `./get_nb_jobs.sh -master <master_server> -username <username> -password <password>`
40+
- `./get_nb_images.sh -master <master_server> -username <username> -password <password>`

snippets/curl/get_nb_images.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
!/bin/sh
2+
3+
#####################n#####################################################
4+
5+
# This script demonstrates the usage of netbackup REST API for listing
6+
# the backup images
7+
8+
# This script requires jq command-line JSON parser
9+
# if your system does not have jq installed, this will not work
10+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
11+
12+
###########################################################################
13+
14+
port=1556
15+
master_server=""
16+
username=""
17+
password=""
18+
domainname=""
19+
domaintype=""
20+
21+
showHelp()
22+
{
23+
echo ""
24+
echo "Invalid command parameters"
25+
echo "Usage:"
26+
echo "./get_nb_images.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
27+
echo ""
28+
exit 1
29+
}
30+
31+
parseArguments()
32+
{
33+
if [ $# -lt 6 ]; then
34+
showHelp
35+
fi
36+
37+
while [ "$1" != "" ]; do
38+
case $1 in
39+
-master)
40+
master_server=$2
41+
;;
42+
-username)
43+
username=$2
44+
;;
45+
-password)
46+
password=$2
47+
;;
48+
-domainname)
49+
domainname=$2
50+
;;
51+
-domaintype)
52+
domaintype=$2
53+
;;
54+
*)
55+
showHelp
56+
;;
57+
esac
58+
shift 2
59+
done
60+
61+
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
62+
showhelp
63+
fi
64+
65+
if [ "${domaintype^^}" = "WINDOWS" ] || [ "${domaintype^^}" = "NT" ]; then
66+
domaintype="nt"
67+
fi
68+
}
69+
70+
###############main############
71+
72+
parseArguments "$@"
73+
74+
basepath="https://$master_server:$port/netbackup"
75+
content_header='content-type:application/json'
76+
77+
##############login#############
78+
79+
uri="$basepath/login"
80+
81+
data=$(jq --arg name $username --arg pass $password --arg dname $domainname --arg dtype $domaintype \
82+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
83+
84+
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
85+
86+
param1="filter=policyType eq 'Standard'"
87+
param2="page[limit]=10"
88+
89+
##############jobs##############
90+
91+
auth_header="authorization:$jwt"
92+
uri="$basepath/catalog/images"
93+
94+
curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_header \
95+
--data-urlencode "$param1" \
96+
--data-urlencode "$param2" \
97+
| \
98+
jq '[.data[]|{IMAGE_ID: .id, POLICY: .attributes.policyName, CLIENT: .attributes.clientName, BACKUP_TIME: .attributes.backupTime}]'
99+
100+
exit 0
101+

snippets/curl/get_nb_jobs.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
!/bin/sh
2+
3+
4+
#####################n#####################################################
5+
6+
# This script demonstrates the usage of netbackup REST API for listing the jobs
7+
8+
# This script requires jq command-line JSON parser
9+
# if your system does not have jq installed, this will not work
10+
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
11+
12+
###########################################################################
13+
14+
port=1556
15+
master_server=""
16+
username=""
17+
password=""
18+
domainname=""
19+
domaintype=""
20+
21+
showHelp()
22+
{
23+
echo ""
24+
echo "Invalid command parameters"
25+
echo "Usage:"
26+
echo "./get_nb_jobs.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
27+
echo ""
28+
exit 1
29+
}
30+
31+
parseArguments()
32+
{
33+
if [ $# -lt 10 ]; then
34+
showHelp
35+
fi
36+
37+
while [ "$1" != "" ]; do
38+
case $1 in
39+
-master)
40+
master_server=$2
41+
;;
42+
-username)
43+
username=$2
44+
;;
45+
-password)
46+
password=$2
47+
;;
48+
-domainname)
49+
domainname=$2
50+
;;
51+
-domaintype)
52+
domaintype=$2
53+
;;
54+
*)
55+
showHelp
56+
;;
57+
esac
58+
shift 2
59+
done
60+
61+
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
62+
showhelp
63+
fi
64+
65+
if [ "${domaintype^^}" = "WINDOWS" ] || [ "${domaintype^^}" = "NT" ]; then
66+
domaintype="nt"
67+
fi
68+
}
69+
70+
###############main#############
71+
72+
parseArguments "$@"
73+
74+
basepath="https://$master_server:$port/netbackup"
75+
content_header='content-type:application/json'
76+
77+
##############login#############
78+
79+
uri="$basepath/login"
80+
81+
data=$(jq --arg name $username --arg pass $password --arg dname $domainname --arg dtype $domaintype \
82+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
83+
84+
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
85+
86+
param1="filter=jobType eq 'BACKUP'"
87+
param2="page[limit]=10"
88+
89+
##############jobs##############
90+
91+
auth_header="authorization:$jwt"
92+
uri="$basepath/admin/jobs"
93+
94+
curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_header \
95+
--data-urlencode "$param1" \
96+
--data-urlencode "$param2" \
97+
| \
98+
jq '[.data[]|{JOBID: .id, TYPE: .attributes.jobType, STATE: .attributes.state, STATUS: .attributes.status}]'
99+
exit 0
100+

0 commit comments

Comments
 (0)