copy checksum from previous session if file hasn't changed.

This commit is contained in:
hjp 2007-11-15 20:17:55 +00:00
parent 1447c7d03c
commit 36d9cdef22
1 changed files with 18 additions and 0 deletions

View File

@ -80,6 +80,7 @@ sub backup2disk {
$self->{last_backup} = $dirs[-1];
$self->{last_backup} = $1 if $self->{last_backup} =~ /(.*)/; # detaint
$self->{last_backup_id} = $self->get_last_session_id();
my $timestamp = $self->{timestamp} || strftime('%Y-%m-%dT%H.%M.%S', localtime);
$self->{this_backup} = $self->{basedir} . "/$timestamp/" . $target->{host} . '/' . $target->{dir};
@ -374,6 +375,14 @@ sub db_record_version {
$target->{id}, $f->{name});
}
if ($f->{t} eq 'f' && !defined($f->{checksum})) {
# this must be a link to the previous version
my $db_pv = $self->{dbh}->selectall_arrayref("select * from versions where file=? and session=?",
{ Slice => {} },
$db_f->[0]{id},
$self->{last_backup_id});
$f->{checksum} = $db_pv->[0]{checksum};
}
$self->{dbh}->do("insert into versions(file,
file_id, file_type, file_size, file_mtime,
file_owner, file_group, file_acl,
@ -410,5 +419,14 @@ sub close_session {
$self->{dbh}->do("update sessions set end_date=? where id=?", {}, time(), $self->{session_id});
}
sub get_last_session_id {
my ($self) = @_;
my $sessions = $self->{dbh}->selectall_arrayref("select * from sessions where prefix=?",
{ Slice => {} },
$self->{last_backup});
die "$self->{last_backup} not a unique prefix" unless @$sessions == 1;
return $sessions->[0]{id};
}
# vim: tw=0 expandtab
1;