Skip to content

Commit c38dff8

Browse files
Merge pull request #18 from VeritasOS/perl-scripts
Perl code snippets
2 parents 1be6e2b + ad1c49f commit c38dff8

File tree

15 files changed

+603
-85
lines changed

15 files changed

+603
-85
lines changed

README.md

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +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
12-
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>`
16-
17-
#### Executing the snippets in Python
18-
Pre-requisites:
19-
- NetBackup 8.1.1 or higher
20-
- python 3.5 or higher
21-
- python modules: `requests, texttable`
8+
#### Executing the snippets for different programming languages
229

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>`
10+
The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
2611

27-
#### Executing the snippets in Perl
2812
Pre-requisites:
2913
- NetBackup 8.1.1 or higher
30-
- See script README for perl requirements and usage
31-
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>`
14+
- See the script's README for the corresponding requirements and usage
4115

4216
#### Tools
4317
The `tools` folder contains utilities that have proven useful in the development of projects using

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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#####################n#####################################################
44

5-
# This script demonstrates the usage of netbackup REST API for listing
5+
# This script demonstrates the usage of netbackup REST API for listing
66
# the backup images
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_images.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 6 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -98,4 +98,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth
9898
jq '[.data[]|{IMAGE_ID: .id, POLICY: .attributes.policyName, CLIENT: .attributes.clientName, BACKUP_TIME: .attributes.backupTime}]'
9999

100100
exit 0
101-

snippets/curl/get_nb_jobs.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# This script demonstrates the usage of netbackup REST API for listing the jobs
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_jobs.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 10 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -97,4 +97,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_
9797
| \
9898
jq '[.data[]|{JOBID: .id, TYPE: .attributes.jobType, STATE: .attributes.state, STATUS: .attributes.status}]'
9999
exit 0
100-

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";

snippets/perl/get_nb_jobs.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_jobs.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::getJobs($fqdn_hostname, $myToken);
57+
58+
print "\nNetBackup Jobs:\n";
59+
netbackup::displayJobs($jsonstring);
60+
61+
netbackup::logout($fqdn_hostname, $myToken);
62+
print "\n";

0 commit comments

Comments
 (0)