/* * Copyright (c) 2009, 2010 Zmanda, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com */ %perlcode %{ =head1 NAME Amanda::Logfile - manage Amanda trace logs =head1 SYNOPSIS use Amanda::Logfile qw( :constants ); use Amanda::Config qw( :getconf config_dir_relative ); for my $logfile (Amanda::Logfile::find_log()) { $logfile = config_dir_relative(getconf($CNF_LOGDIR)) . "/" . $logfile; my $hdl = Amanda::Logfile::open_logfile($logfile); while (my ($type, $prog, $str) = Amanda::Logfile::get_logline($hdl)) { if ($type == $L_INFO) { my $pname = Amanda::Logfile::program_t_to_string($prog); print "Found info line from $pname: $str\n"; } } Amanda::Logfile::close_logfile($hdl); my @dumps = Amanda::Logfile::search_logfile("TapeLabel-001", "19780615", $logfile, 1); my @matching = Amanda::Logfile::dumps_match([@dumps], "myhost", "/usr", undef, undef, 0); for my $dump (@matching) { print "$dump->{'label'}:$dump->{'filenum'} = $dump->{'hostname'}:$dump->{'disk'}\n"; } } =head1 RAW LOGFILE ACCESS This section corresponds to the C C module. Raw access to logfiles is accomplished by opening a logfile and fetching log lines one by one via the C function. A log line is represented by a list C<($type, $prog, $string)> where C<$type> is one of the C constants (available in export tag C), C<$prog> is one of the C constants (available in export tag C), and C<$str> is the remainder of the line. Both sets of constants are also available in the usual C export tag. Both families of constants can be converted to symbolic names with C and C, respectively. =head2 FUNCTIONS Use these functions to read a logfile: =over =item C Opens a logfile for reading, returning an opaque log file handle. Returns C and sets C<$!> on failure. =item C Closes a log file handle. =item C Returns a list as described above representing the next log line in C<$handle>, or nothing at the end of the logfile. =back To write a logfile, call C. On the first call, this function opens and locks C<$logdir/log>; subsequent calls just append to this file. As such, this function is only appropriate for situations where C will be invoked later to rename C<$logdir/log> to C<$logdir/log.$timestamp.$n>. All of the functions in this section can be imported by name if desired. =head2 Amanda::Find::find_result_t objects These objects contain information about dumps, as read from logfiles. Instance variables are: =over =item C =item C =item C =item C =item C