This commit is contained in:
hjp 2007-06-18 01:00:29 +00:00
parent 9f46b37420
commit 12c52a7655
2 changed files with 16 additions and 10 deletions
backup
lib/Simba

4
backup
View File

@ -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 => '/' }
]);

View File

@ -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);