From 12c52a7655b4899ec4e7f68a1d7ab52bbb3371aa Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 18 Jun 2007 01:00:29 +0000 Subject: [PATCH] logging. --- backup | 4 +++- lib/Simba/CA.pm | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/backup b/backup index fa58ca7..d4b6d16 100755 --- a/backup +++ b/backup @@ -5,7 +5,9 @@ use Simba::CA; $ENV{PATH} = "/usr/bin"; -my $ca = Simba::CA->new(); +open(my $log, '>>', '/var/log/simba/ca.log'); +$log->autoflush(1); +my $ca = Simba::CA->new({fh_log => $log}); $ca->targets([ { host => 'bernon.wsr.ac.at', dir => '/' } ]); diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index 52ba8c7..0f13b73 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -82,12 +82,15 @@ sub backup2disk { $list_cfd->printflush("list $target->{dir}\n"); # XXX - encode! close($list_cfd); while (<$list_dfd>) { + chomp; + $self->log(10, "file: $_"); # split into fields my $f = $self->parse($_); # if file is already present if ($f->{t} eq 'f') { if($self->present($f)) { link("$self->{last_backup}/$f->{name}", "$self->{this_backup}/$f->{name}") or die; # XXX + $self->log(10, "linked"); } else { # else request from da @@ -108,11 +111,11 @@ sub backup2disk { my $rc = read($file_dfd, $buffer, min($size, $BUFSIZE)); if (!defined($rc)) { # I/O error - print STDERR "error reading from data socket: $!"; + $self->log(5, "error reading from data socket: $!"); last; } elsif ($rc == 0) { # premature EOF. - print STDERR "unexpected EOF reading from data socket"; + $self->log(5, "unexpected EOF reading from data socket"); last; } $file_bfd->print($buffer); @@ -123,17 +126,18 @@ sub backup2disk { my $trailer = <$file_dfd>; # should be empty line $trailer = <$file_dfd>; if ($trailer =~ /^fail /) { - print STDERR $trailer; + $self->log(5, $trailer); } elsif ($trailer =~ /^chk sha1 (\w+)/) { if ($sha1->hexdigest ne $1) { - print STDERR "checksum error\n"; + $self->log(5, "checksum error\n"); } } else { - print STDERR "unexpected trailer $trailer\n"; + $self->log(5, "unexpected trailer $trailer\n"); } $self->setmeta($f); + $self->log(10, "stored"); } else { - print STDERR "unexpected header $header\n"; + $self->log(5, "unexpected header $header\n"); } } } elsif ($f->{t} eq 'd') { @@ -150,7 +154,7 @@ sub backup2disk { # lchown, lchmod, etc. } else { # create local copy (or insert into DB only?) - print STDERR "ignored $_\n"; + $self->log(5, "ignored $_\n"); } # insert into DB. } @@ -248,9 +252,9 @@ my %permstrbits = ( sub setmeta { my ($self, $f) = @_; my $fn = "$self->{this_backup}/$f->{name}"; - print STDERR "$fn is tainted!" if tainted($fn); + $self->log(3, "$fn is tainted!") if tainted($fn); my $mode = $self->acl2mode($f); - print STDERR "$mode is tainted!" if tainted($mode); + $self->log(3, "$mode is tainted!") if tainted($mode); chmod($mode, $fn); chown($self->name2uid($f->{o}), $self->name2gid($f->{g}), $fn); utime(time, $f->{m}, $fn);