+push @EXPORT_OK, qw($P_AMDUMP);
+push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMDUMP);
+
+$_program_t_VALUES{"P_AMDUMP"} = $P_AMDUMP;
+
+push @EXPORT_OK, qw($P_AMIDXTAPED);
+push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMIDXTAPED);
+
+$_program_t_VALUES{"P_AMIDXTAPED"} = $P_AMIDXTAPED;
+
+push @EXPORT_OK, qw($P_AMFETCHDUMP);
+push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMFETCHDUMP);
+
+$_program_t_VALUES{"P_AMFETCHDUMP"} = $P_AMFETCHDUMP;
+
+push @EXPORT_OK, qw($P_AMCHECKDUMP);
+push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMCHECKDUMP);
+
+$_program_t_VALUES{"P_AMCHECKDUMP"} = $P_AMCHECKDUMP;
+
+push @EXPORT_OK, qw($P_AMVAULT);
+push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMVAULT);
+
+$_program_t_VALUES{"P_AMVAULT"} = $P_AMVAULT;
+
+#copy symbols in program_t to constants
+push @{$EXPORT_TAGS{"constants"}}, @{$EXPORT_TAGS{"program_t"}};
+
+push @EXPORT_OK, qw(find_log search_logfile dumps_match log_rename
+ match_host match_disk match_datestamp match_level);
+
+push @EXPORT_OK, qw($amanda_log_trace_log);
+
+push @EXPORT_OK, qw(find_all_logs find_latest_log
+ get_current_log_timestamp
+ make_stats);
+
+
+sub find_all_logs
+{
+ my $logdir = shift @_ || config_dir_relative(getconf($CNF_LOGDIR));
+
+ opendir my $logdh, $logdir or die("can't read $logdir");
+ my @logfiles = sort grep { m{^log\.\d+\.\d+$} } readdir $logdh;
+
+ return @logfiles;
+}
+
+sub find_latest_log
+{
+ my $logdir = shift @_;
+ my @logs = find_all_logs($logdir || ());
+ return $logs[-1];
+}
+
+use Amanda::Config;
+use Amanda::Debug;
+
+sub get_current_log_timestamp
+{
+ my $logfile = Amanda::Config::config_dir_relative(
+ Amanda::Config::getconf($Amanda::Config::CNF_LOGDIR)) . "/log";
+ if (! -f $logfile) {
+ Amanda::Debug::warning("no current logfile '$logfile'");
+ return undef;
+ }
+
+ my $logh = open_logfile("$logfile");
+ if (!$logh) {
+ Amanda::Debug::warning("could not open logfile '$logfile'");
+ return undef;
+ }
+ while (my ($type, $prog, $str) = get_logline($logh)) {
+ if ($type == $L_START) {
+ my ($ts) = ($str =~ /date (\d+)/);
+ return $ts if $ts;
+ }
+ }
+
+ # no timestamp, apparently
+ Amanda::Debug::warning("no current timestamp found in logfile");
+ return undef;
+}
+
+sub make_stats {
+ my ($size, $duration, $orig_kb) = @_;
+
+ $duration = 0.1 if $duration <= 0; # prevent division by zero
+ my $kb = $size/1024;
+ my $kps = "$kb.0"/$duration; # Perlish cast from BigInt to float
+
+ if (defined $orig_kb) {
+ return sprintf("[sec %f kb %d kps %f orig-kb %d]", $duration, $kb, $kps, $orig_kb);
+ } else {
+ return sprintf("[sec %f kb %d kps %f]", $duration, $kb, $kps);
+ }
+}
+