Skip to content

Commit 6119f76

Browse files
author
sandeep parmar
committed
Curl samples for listing nb jobs and backup images
Added Curl client samples for invoking two rest APIs /admin/jobs /catalog/images
1 parent 89b76a2 commit 6119f76

File tree

3 files changed

+208
-0
lines changed

3 files changed

+208
-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
37+
38+
Use the following commands to run the curl samples.
39+
- `./nb_jobs.sh -master <master_server> -username <username> -password <password>`
40+
- `./nb_images.sh -master <master_server> -username <username> -password <password>`

snippets/curl/get_nb_images.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
19+
showHelp()
20+
{
21+
echo ""
22+
echo "Invalid command parameters"
23+
echo "Usage:"
24+
echo "./nb_images.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
25+
echo ""
26+
exit 1
27+
}
28+
29+
parseArguments()
30+
{
31+
if [ $# -lt 6 ]; then
32+
showHelp
33+
fi
34+
35+
while [ "$1" != "" ]; do
36+
case $1 in
37+
-master)
38+
master_server=$2
39+
;;
40+
-username)
41+
username=$2
42+
;;
43+
-password)
44+
password=$2
45+
;;
46+
-domainname)
47+
domainname=$2
48+
;;
49+
-domaintype)
50+
domaintype=$2
51+
;;
52+
*)
53+
showHelp
54+
;;
55+
esac
56+
shift 2
57+
done
58+
59+
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
60+
showhelp
61+
fi
62+
63+
if [ "${domaintype^^}" = "WINDOWS" ] || [ "${domaintype^^}" = "NT" ]; then
64+
domaintype="nt"
65+
fi
66+
}
67+
68+
###############main############
69+
70+
parseArguments "$@"
71+
72+
basepath="https://$master_server:$port/netbackup"
73+
content_header='content-type:application/json'
74+
75+
##############login#############
76+
77+
uri="$basepath/login"
78+
79+
data=$(jq --arg name $username --arg pass $password --arg dname $domainname --arg dtype $domaintype \
80+
--null-input '{userName: $name, password: $pass, domainName: $dname, domainType: $dtype}')
81+
82+
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
83+
84+
param1="filter=policyType eq 'Standard'"
85+
param2="page[limit]=10"
86+
87+
##############jobs##############
88+
89+
auth_header="authorization:$jwt"
90+
uri="$basepath/catalog/images"
91+
92+
curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_header \
93+
--data-urlencode "$param1" \
94+
--data-urlencode "$param2" \
95+
| \
96+
jq '[.data[]|{IMAGE_ID: .id, POLICY: .attributes.policyName, CLIENT: .attributes.clientName, BACKUP_TIME: .attributes.backupTime}]'
97+
98+
exit 0
99+

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 "./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)