Perl netbackup script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl netbackup script?
# 1  
Old 12-30-2009
Perl netbackup script?

Hi,

I'm currently working on adapting a netbackup script to run reports about the backup duration of clients and how many kb's written.
But I'm stuck at the time stamp of the backup.

I want to see in the sheet:
Sat Nov 07 00:00:26 2009 (1257548426)
But i get:
26 2009 (1257548426)

Code:
#!/usr/bin/perl


$DATA = system("/usr/openv/netbackup/bin/admincmd/bpimagelist -L -hoursago 24 > /tmp/Tapelog.txt"); # || die qq (Can't execute command bpimagelist.cmd);
#Tapelog.txt is made from bpimagelist -L -hoursago 24, this is just a rough list.  See Tapes_To_Be_Pulled for final output.

open(CSVFILE, ">./MK_Tapes_To_Be_Pulled.csv") || die qq(Can't open "Tapes_To_Be_Pulled.csv " for output.\n);
open (LINKLIST, "</tmp/Tapelog.txt") or die $!;

#creates Tapes_To_Be_Pulled.csv (output file)
print CSVFILE "Client,Policy,Schedule Type,Backup Time, Elapsed Time, Kilobytes,Media Date\n";
#Below parses Tapelog.txt for the listed fields
while (<LINKLIST>) {
    chomp;
     s{\d+:\d+:\d+\s*\([^)]*\)
    }{}x; #Takes C time off of the Media Date listing, or any other time listing in logfile.
    $_=~ s/^\s+//; $_ =~ s/\s+$//;
    my ($key, $value) = ($_=~ m!(.+):(.+)!);
    $value =~ s/^\s+//; $value =~ s/\s+$//;
    print "$key,$value\n";
    $client = $value if (/^Client:/);
    $policy = $value if (/^Policy:/);
    $schedule = $value if (/^Schedule Type/);
    $backuptime= substr($value if (/^Backup Time/));
    $elapsedtime = $value if (/^Elapsed Time/);
    $id = $value if (/^ID/);
    $mediatape = $value if (/^Media Date: /);
    $kilobytes = $value if (/^Kilobytes/);
    print CSVFILE  "$client,$policy,$schedule,$backuptime,$elapsedtime,$kilobytes,$mediatape\n" if /resume/ ;
}


close(CSVFILE) || die qq(Can't close output file "Tapes_To_Be_Pulled.csv".\n);


Last edited by jld; 12-30-2009 at 09:53 AM..
# 2  
Old 12-30-2009
Post in english please
# 3  
Old 12-30-2009
Can you post your "Tapelog.txt" file, or a sample if it is too big or confidential ?

tyler_durden
# 4  
Old 12-31-2009
Tapelog.txt

Code:
Client:            babbage
Backup ID:         babbage_1262120428
Policy:            Unix
Policy Type:       Standard (0)
Proxy Client:      (none specified)
Creator:           NetBackup
Name1:             (none specified)
Sched Label:       Incrs
Schedule Type:     INCR (1)
Retention Level:   1 month (3)
Backup Time:       Tue Dec 29 22:00:28 2009 (1262120428)
Elapsed Time:      103 second(s)
Expiration Time:   Fri Jan 29 22:00:28 2010 (1264798828)
Compressed:        no
Client Encrypted:  no
Kilobytes:         32
Number of Files:   0
Number of Copies:  1
Number of Fragments:   1
Histogram:         -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
DB Compressed:     no
Files File Name:   Unix_1262120428_INCR.f
Previous Backup Files File Name:   (none specified)
Parent Backup Image File Name:   (none specified)
SW Version:        (none specified)
Options:           0x0
MPX:               1
TIR Info:          0
TIR Expiration:    Thu Jan 01 01:00:00 1970 (0)
Keyword:           (none specified)
Ext Security Info: no
File Restore Raw:  no
Image Dump Level:  0
File System Only:  no
Object Descriptor: (none specified)
Previous BI Time:  Thu Jan 01 01:00:00 1970 (0)
BI Full Time:      Thu Jan 01 01:00:00 1970 (0)
Request Pid:       0
Backup Status:     0
Stream Number:     5
Backup Copy:       Standard (0)
Files File size:     447
PFI type:     0
IMAGE_ATTRIBUTE:     0
Primary Copy:      1
Image Type:        0  (Regular)
Job ID:            89629
Num Resumes:       0
Resume Expiration: Thu Jan 01 01:00:00 1970 (0)
Data Classification:    (none specified)
Data_Classification_ID: (none specified)
Storage Lifecycle Policy:    (none specified)
STL_Completed:      0
Snap Time:      Thu Jan 01 01:00:00 1970 (0)
Copy number:       1
 Fragment:         1
 Kilobytes:        32
 Remainder:        512
 Media Type:       Media Manager (2)
 Density:          hcart2 (14)
 File Num:         28
 ID:               H445L2
 Host:             thor
 Block Size:       524288
 Offset:           23917
 Media Date:       Sat Dec 26 00:00:11 2009 (1261782011)
 Dev Written On:   0
 Flags:            0x0  
 Media Descriptor:        ?
 Expiration Time:  Fri Jan 29 22:00:28 2010 (1264798828)
 MPX:              1
 retention_lvl:    1 month (3)
 Try to Keep Time:  Thu Jan 01 01:00:00 1970 (0)
 Copy Creation Time:  Tue Dec 29 22:02:11 2009 (1262120531)
 checkpoint:       0
 resume num:       0
 Key tag:          *NULL*

# 5  
Old 01-03-2010
Hi,

Thanks for posting the data file. I've made a few changes to your Perl script - changed the regex for splitting records, and removed some extraneous stuff.

Try this to see if it works for you:

Code:
$
$ cat netbkup.pl
#!/usr/bin/perl -w
$DATA = system("/usr/openv/netbackup/bin/admincmd/bpimagelist -L -hoursago 24 > /tmp/Tapelog.txt");
open (CSVFILE, ">MK_Tapes_To_Be_Pulled.csv") or die "Can't open MK_Tapes_To_Be_Pulled.csv for output: $!";
open (LINKLIST, "</tmp/Tapelog.txt") or die "Can't open /tmp/Tapelog.txt: $!";
print CSVFILE "Client,Policy,Schedule Type,Backup Time, Elapsed Time, Kilobytes,Media Date\n";
while (<LINKLIST>) {
  chomp;
  s/^\s+//;
  s/\s+$//;
  ($key, $value) = ($_=~ m!(.*?):(.+)!);
  $value =~ s/^\s+//;
  $value =~ s/\s+$//;
  printf("%-40s %-s\n",$key,$value);
  $client = $value if /^Client:/;
  $policy = $value if /^Policy:/;
  $schedule = $value if /^Schedule Type/;
  $backuptime = $value if /^Backup Time/;
  $elapsedtime = $value if /^Elapsed Time/;
  $mediatape = $value if /^Media Date: /;
  $kilobytes = $value if /^Kilobytes/;
  print CSVFILE  "$client,$policy,$schedule,$backuptime,$elapsedtime,$kilobytes,$mediatape\n" if /resume/ ;
}
close (CSVFILE)  or die "Can't close output file Tapes_To_Be_Pulled.csv: $!";
close (LINKLIST) or die "Can't close file /tmp/Tapelog.txt: $!";
$
$

tyler_durden
# 6  
Old 01-04-2010
Thanks, I will check tomorrow iff the script will works now.

---------- Post updated 04-01-10 at 12:06 PM ---------- Previous update was 03-01-10 at 03:39 PM ----------

The script works, but there are errors at the beginning when I ran the script.

bash-3.00# ./test
Name "main:SmilieATA" used only once: possible typo at ./test line 2.
Use of uninitialized value in substitution (s///) at ./test line 11, <LINKLIST> line 1.
Use of uninitialized value in substitution (s///) at ./test line 12, <LINKLIST> line 1.
Use of uninitialized value in printf at ./test line 13, <LINKLIST> line 1.
Use of uninitialized value in printf at ./test line 13, <LINKLIST> line 1.

---------- Post updated at 12:07 PM ---------- Previous update was at 12:06 PM ----------

Name "main:: DATA" used only once: possible typo at ./test line 2.
Use of uninitialized value in substitution (s///) at ./test line 11, <LINKLIST> line 1.
Use of uninitialized value in substitution (s///) at ./test line 12, <LINKLIST> line 1.
Use of uninitialized value in printf at ./test line 13, <LINKLIST> line 1.
Use of uninitialized value in printf at ./test line 13, <LINKLIST> line 1.
# 7  
Old 01-04-2010
Those are warnings actually; set by the -w flag in the shebang.
Remove the assignment to $DATA. The warning is printed because $DATA is assigned but never used anywhere else. (As such, you don't have to assign it in the first place.)
My guess is that the uninitialized value warning is printed due to blank lines in your Tapelog.txt file. There's nothing to substitute at that point, so Perl prints a warning. On encountering a blank line, you may want to skip it and move on to the next iteration of the "while" loop.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Netbackup Perl Script

please let me know if you can help me out. I need to modify a perl netbackup script to do the following. Will need to enhance a script to do the following: to initiate an incremental during the week and a full only during the weekend. to check if there is another full currently running... (0 Replies)
Discussion started by: Lia123
0 Replies

3. UNIX for Dummies Questions & Answers

Netbackup Report

Would I be able to get the report (text format) of an activity monitor view of a netbackup via command line? I am trying to make a script out of it that would be run daily an be saved in a txt document which would could be viewed for history purpose. I need minimal details only like policy name,... (0 Replies)
Discussion started by: ryan_estiya
0 Replies

4. Solaris

veritas netbackup

Hi All, We are currently running Veritas netbackup. We are currently having a few issues where were unable to log in due to several errors. Out usual fix for this is to recycle the backup servers however due to the nature of the information being backed up this is done by someone else and... (1 Reply)
Discussion started by: rickyclayton201
1 Replies

5. UNIX for Dummies Questions & Answers

Netbackup 6 Question

What is the command to find out if a policy has been run and if it has the date it was last run? (0 Replies)
Discussion started by: mr_crosby
0 Replies

6. Filesystems, Disks and Memory

Netbackup Questions

I have 2 questions maybe those netbackup experts and gurus in the house can help. Firstly, is there a particular location maybe under /usr/openv where I can find a diretory or file which contains all the backup policy information, so lets say If someone were to physically delete all the... (3 Replies)
Discussion started by: sparcguy
3 Replies

7. HP-UX

Netbackup Installation

Hello all. I have a HP-UX 11.11 system that I need to install Netbackup 6.5 onto. After I mount the cd drive and run the 'install' command, it comes back with the following error: usage: install file WHAT options is it talking about? When I look at the documentation from Netbackup, it... (4 Replies)
Discussion started by: impunchdrunk
4 Replies

8. Solaris

Netbackup on Solaris 8

Hi, Anyone know netbackup 3.4 on Solaris 8 . Currently I use root to perform backup / monitoring ...etc . Can I create a user call "backup" and perform the same task What permission should I give the "backup" user . (1 Reply)
Discussion started by: civic2005
1 Replies

9. Filesystems, Disks and Memory

Netbackup question

Hello, I am setting up scripts to do shadow image backups but have found a pitfall I cannot figure out how to work around. Basically what I need to figure out is how to launch a bunch of bpbackups, and then have the script pause until all of the children have exited. The problem is that bpbackup... (2 Replies)
Discussion started by: 98_1LE
2 Replies

10. UNIX for Dummies Questions & Answers

Veritas NetBackup

Veritas NetBackup, how does it work?? I mean, I know it is used for backups and restores but really, can anybody give me a brief or any explanation that sums up basically what it is about besides the fact that it does backups and restores??? Please, if you have any information, I would appreciate... (2 Replies)
Discussion started by: TRUEST
2 Replies
Login or Register to Ask a Question