#
#========================================================================
#
-# Version 3.0.0alpha, released 23 Jan 2006.
+# Version 3.0.0, released 28 Jan 2007.
#
# See http://backuppc.sourceforge.net.
#
my $bpc = bless {
%$paths,
- Version => '3.0.0alpha',
+ Version => '3.0.0',
}, $class;
$bpc->{storage} = BackupPC::Storage->new($paths);
if ( !$noUserCheck
&& $bpc->{Conf}{BackupPCUserVerify}
&& $> != (my $uid = (getpwnam($bpc->{Conf}{BackupPCUser}))[2]) ) {
- print(STDERR "Wrong user: my userid is $>, instead of $uid"
+ print(STDERR "$0: Wrong user: my userid is $>, instead of $uid"
. " ($bpc->{Conf}{BackupPCUser})\n");
+ print(STDERR "Please su $bpc->{Conf}{BackupPCUser} first\n");
return;
}
return $bpc;
my($pid, $out, $allOut);
local(*CHILD);
+ $? = 0;
if ( (ref($cmd) eq "ARRAY" ? $cmd->[0] : $cmd) =~ /^\&/ ) {
$cmd = join(" ", $cmd) if ( ref($cmd) eq "ARRAY" );
print(STDERR "cmdSystemOrEval: about to eval perl code $cmd\n")
}
}
+#
+# This is sort() compare function, used below.
+#
+# New client LOG names are LOG.MMYYYY. Old style names are
+# LOG, LOG.0, LOG.1 etc. Sort them so new names are
+# first, and newest to oldest.
+#
+sub compareLOGName
+{
+ my $na = $1 if ( $a =~ /LOG\.(\d+)(\.z)?$/ );
+ my $nb = $1 if ( $b =~ /LOG\.(\d+)(\.z)?$/ );
+
+ $na = -1 if ( !defined($na) );
+ $nb = -1 if ( !defined($nb) );
+
+ if ( length($na) >= 5 && length($nb) >= 5 ) {
+ #
+ # Both new style: format is MMYYYY. Bigger dates are
+ # more recent.
+ #
+ my $ma = $2 * 12 + $1 if ( $na =~ /(\d+)(\d{4})/ );
+ my $mb = $2 * 12 + $1 if ( $nb =~ /(\d+)(\d{4})/ );
+ return $mb - $ma;
+ } elsif ( length($na) >= 5 && length($nb) < 5 ) {
+ return -1;
+ } elsif ( length($na) < 5 && length($nb) >= 5 ) {
+ return 1;
+ } else {
+ #
+ # Both old style. Smaller numbers are more recent.
+ #
+ return $na - $nb;
+ }
+}
+
+#
+# Returns list of paths to a clients's (or main) LOG files,
+# most recent first.
+#
+sub sortedPCLogFiles
+{
+ my($bpc, $host) = @_;
+
+ my(@files, $dir);
+
+ if ( $host ne "" ) {
+ $dir = "$bpc->{TopDir}/pc/$host";
+ } else {
+ $dir = "$bpc->{LogDir}";
+ }
+ if ( opendir(DIR, $dir) ) {
+ foreach my $file ( readdir(DIR) ) {
+ next if ( !-f "$dir/$file" );
+ next if ( $file ne "LOG" && $file !~ /^LOG\.\d/ );
+ push(@files, "$dir/$file");
+ }
+ closedir(DIR);
+ }
+ return sort(compareLOGName @files);
+}
+
1;