Amanda::Logfile - manage Amanda trace logs
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"; } }
This section corresponds to the C logfile
module.
Raw access to logfiles is accomplished by opening a logfile and
fetching log lines one by one via the get_logline
function.
A log line is represented by a list ($type, $prog, $string)
where $type
is one of the L_*
constants (available in export tag logtype_t
), $prog
is one of the P_*
constants (available in export tag program_t
), and
$str
is the remainder of the line. Both sets of constants are also available
in the usual constants
export tag. Both families of constants can be
converted to symbolic names with logtype_t_to_string
and
program_t_to_string
, respectively.
Use these functions to read a logfile:
open_logfile($filename)
Opens a logfile for reading, returning an opaque log file
handle. Returns undef
and sets $!
on failure.
close_logfile($handle)
Closes a log file handle.
get_logline($handle)
Returns a list as described above representing the next log line in
$handle
, or nothing at the end of the logfile.
To write a logfile, call log_add($logtype, $string)
. On the first call,
this function opens and locks $logdir/log
; subsequent calls just append to
this file. As such, this function is only appropriate for situations where
log_rename
will be invoked later to rename $logdir/log
to
$logdir/log.$timestamp.$n
.
If you need to write a log entry for another program, for example to simulate
taper entries, call log_add_full($logtype, $pname, $string)
.
All of the functions in this section can be imported by name if desired.
Many trace log entries have a statistics entry in what used to be the error
message slot, of the form [sec .. kb .. kps ..]
. The function make_stats
will create such an entry for you:
make_stats($size, $duration, $orig_kb);
Note that $orig_kb
can be undefined, in which case it will not appear in
the statistics output.
These objects contain information about dumps, as read from logfiles. Instance variables are:
To rename the current logfile to a datestamped logfile, call log_rename($ts)
where $ts
is the write timestamp for this dump. The
get_current_log_timestamp()
function will calculate this timestamp,
returning undef
on error.
Note that the format for these variables are based on that found in
the logfiles. In particular, timestamp
is the timestamp for the run
in which the client dump took place, and not for the timestamp of the
logfile.
Functions in this section extract information from logfiles.
find_log()
Return a list of logfiles for active tapes. The tapelist must be loaded before this function is called (see Amanda::Tapelist). This function uses the C API which indexes logfiles with tapes. If there is no corresponding tape, the logfile will not be found.
find_all_logs([dir])
Return a list of all logs the configuration. An optional directory argument
can be specified, if not present, find_all_logs
checks LOGDIR
.
find_latest_log([dir])
Returns the most recent logfile in the list of logfiles returned by
find_all_logs
. The optional directory argument is passed to
find_all_logs
.
search_logfile($label, $datestamp, $logfile, $add_missing_disks)
Return all results in $logfile
matching $label
and
$datestamp
. If $add_missing_disks
is true, then any disks in
the logfile not present in the disklist are added to the disklist;
otherwise, such dumps are skipped.
search_holding_disk()
Return results for all holding-disk files. Results are similar to those from search_logfile.
dumps_match([@results], $hostname, $diskname, $datestamp, $level, $ok)
Return a filtered version of @results
containing only results that
match the given expressions. If $ok
is true, don't match partial
results. Note that $level
is given as a string, since it is a
match expression.
dumps_match_dumpspecs([@results], [@dumpspecs], $ok)
Return a filtered version of @results
, containing only results that match
one or more of the dumpspecs. $ok
is as for dumps_match
. Supplying no
dumpspecs will result in an empty return value. If multiple dumpspecs match
the same result, that result will be returned multiple times.
All of these functions can be imported by name.
This package provides $amanda_log_trace_log
, which sends die
messages (and any g_error
or g_critical
calls from C) to the
trace log. Use it like this:
use Amanda::Logfile qw( $amanda_log_trace_log ); # ... Amanda::Debug::add_amanda_log_handler($amanda_log_trace_log);
This page was automatically generated Tue Feb 21 19:14:01 2012 from the Amanda source tree, and documents the most recent development version of Amanda. For documentation specific to the version of Amanda on your system, use the 'perldoc' command.