Skip to content

Commit 77ae62e

Browse files
authored
Merge branch 'master' into feature/create_policy_with_defaults
2 parents 7a2a1b7 + c38dff8 commit 77ae62e

File tree

17 files changed

+911
-77
lines changed

17 files changed

+911
-77
lines changed

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@ Contains code samples to invoke NetBackup REST API using different programming l
55
#### Disclaimer
66
These scripts are only meant to be used as a reference. Please do not use these in production.
77

8-
#### Executing the snippets in PowerShell
9-
Pre-requisites:
10-
- NetBackup 8.1.1 or higher
11-
- Powershell 5.0 or higher
8+
#### Executing the snippets for different programming languages
129

13-
Use the following commands to run the powershell samples.
14-
- `.\Get-NB-Images.ps1 -nbmaster <masterServer> -username <username> -password <password>`
15-
- `.\Get-NB-Jobs.ps1 -nbmaster <masterServer> -username <username> -password <password>`
10+
The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
1611

17-
#### Executing the snippets in Python
1812
Pre-requisites:
1913
- NetBackup 8.1.1 or higher
20-
- python 3.5 or higher
21-
- python modules: `requests, texttable`
22-
23-
Use the following commands to run the python samples.
24-
- `python -W ignore get_nb_images.py -nbmaster <masterServer> -username <username> -password <password>`
25-
- `python -W ignore get_nb_jobs.py -nbmaster <masterServer> -username <username> -password <password>`
26-
27-
#### Executing the snippets in Perl
28-
Pre-requisites:
29-
- NetBackup 8.1.1 or higher
30-
- See script README for perl requirements and usage
14+
- See the script's README for the corresponding requirements and usage
3115

3216
#### Executing the recipes in Perl
3317
Pre-requisites:
@@ -38,4 +22,9 @@ Use the following commands to run the perl samples.
3822
- `perl create_policy_step_by_step.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
3923
- `perl create_policy_in_one_step.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
4024
- `perl api_requests_images.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
41-
- `perl api_requests_image_contents.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
25+
- `perl api_requests_image_contents.pl -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]`
26+
27+
#### Tools
28+
The `tools` folder contains utilities that have proven useful in the development of projects using
29+
NetBackup REST APIs, but do not provide any API usage examples. Again, these tools are not for
30+
production use, but they may be of some use in your work.

snippets/curl/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### NetBackup API Code Samples for curl
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using curl.
4+
5+
#### Disclaimer
6+
7+
These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.1 or higher
12+
- curl 7.51.0 or higher
13+
- jq command-line parser (https://github.com/stedolan/jq/releases)
14+
15+
#### Executing the snippets in curl
16+
17+
Use the following commands to run the curl samples.
18+
- `./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`
19+
- `./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`

snippets/curl/get_nb_images.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 -nbmaster <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+
-nbmaster)
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

snippets/curl/get_nb_jobs.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 -nbmaster <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+
-nbmaster)
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

snippets/perl/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### NetBackup API Code Samples for Perl
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using Perl.
4+
5+
#### Disclaimer
6+
7+
These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.1 or higher
12+
- Perl v5.18.2
13+
- Perl modules Text::Table, JSON and LWP
14+
15+
#### Executing the snippets in Perl
16+
17+
Job Details:
18+
19+
- Use the following command to obtain the job details from your NetBackup Master server:
20+
- `perl get_nb_jobs.pl -nbmaster <master_server> -username <username> -password <password> [-domainname <domain_name>] [-domaintype <domain_type>] [--verbose]`
21+
22+
23+
Catalog Image Details:
24+
25+
- Use the following command to obtain the catalog image details from your NetBackup Master server:
26+
- `perl get_nb_images.pl -nbmaster <master_server> -username <username> -password <password> [-domainname <domain_name>] [-domaintype <domain_type>] [--verbose]`

snippets/perl/get_nb_images.pl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#Load module netbackup.pm from current directory
2+
use lib '.';
3+
4+
use netbackup;
5+
use strict;
6+
use warnings;
7+
use Getopt::Long qw(GetOptions);
8+
9+
sub printUsage {
10+
print "\nUsage : perl get_nb_images.pl -nbmaster <master_server> -username <username> -password <password> [-domainname <domain_name>] [-domaintype <domain_type>] [--verbose]\n\n";
11+
die;
12+
}
13+
14+
my $fqdn_hostname;
15+
my $username;
16+
my $password;
17+
my $domainname;
18+
my $domaintype;
19+
my $verbose;
20+
21+
GetOptions(
22+
'nbmaster=s' => \$fqdn_hostname,
23+
'username=s' => \$username,
24+
'password=s' => \$password,
25+
'domainname=s' => \$domainname,
26+
'domaintype=s' => \$domaintype,
27+
'verbose' => \$verbose
28+
) or printUsage();
29+
30+
if (!$fqdn_hostname || !$username || !$password) {
31+
printUsage();
32+
}
33+
34+
if($verbose){
35+
print "\nRecieved the following parameters : \n";
36+
print " FQDN Hostname : $fqdn_hostname\n";
37+
print " Username : $username\n";
38+
print " Password : $password\n";
39+
if ($domainname) {
40+
print " Domain Name : $domainname\n";
41+
}
42+
if ($domaintype) {
43+
print " Domain Type : $domaintype\n";
44+
}
45+
}
46+
47+
print "\n";
48+
my $myToken;
49+
if ($domainname && $domaintype) {
50+
$myToken = netbackup::login($fqdn_hostname, $username, $password, $domainname, $domaintype);
51+
}
52+
else{
53+
$myToken = netbackup::login($fqdn_hostname, $username, $password);
54+
}
55+
56+
my $jsonstring = netbackup::getCatalogImages($fqdn_hostname, $myToken);
57+
58+
print "\nNetBackup Catalog Images:\n";
59+
netbackup::displayCatalogImages($jsonstring);
60+
61+
netbackup::logout($fqdn_hostname, $myToken);
62+
print "\n";

0 commit comments

Comments
 (0)