(late commit)
Improved search for last session (now only finds sessions which were completed successfully). Some speed optimizations (not very successfull, iirc).
This commit is contained in:
parent
1f6f4c2949
commit
f8856de2c9
|
@ -152,11 +152,7 @@ sub backup2disk {
|
||||||
$self->{target} = $target;
|
$self->{target} = $target;
|
||||||
|
|
||||||
# get previous generation
|
# get previous generation
|
||||||
my @dirs = glob($self->{basedir} . '/????-??-??T??.??.??/' . $target->{host} . '/' . $target->{dir});
|
$self->get_last_session();
|
||||||
|
|
||||||
$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);
|
my $timestamp = $self->{timestamp} || strftime('%Y-%m-%dT%H.%M.%S', localtime);
|
||||||
$self->{this_backup} = $self->{basedir} . "/$timestamp/" . $target->{host} . '/' . $target->{dir};
|
$self->{this_backup} = $self->{basedir} . "/$timestamp/" . $target->{host} . '/' . $target->{dir};
|
||||||
|
@ -178,6 +174,9 @@ sub backup2disk {
|
||||||
# split into fields
|
# split into fields
|
||||||
chomp;
|
chomp;
|
||||||
my $f = $self->parse($_);
|
my $f = $self->parse($_);
|
||||||
|
if ($count % 1000 == 0) {
|
||||||
|
$self->log(9, "file $count: $f->{name}");
|
||||||
|
}
|
||||||
|
|
||||||
my $success = 1;
|
my $success = 1;
|
||||||
if ($f->{t} eq 'f') {
|
if ($f->{t} eq 'f') {
|
||||||
|
@ -201,6 +200,7 @@ sub backup2disk {
|
||||||
# insert into DB.
|
# insert into DB.
|
||||||
$self->db_record_version($target, $f) if ($success);
|
$self->db_record_version($target, $f) if ($success);
|
||||||
}
|
}
|
||||||
|
$self->flush_insert_instances();
|
||||||
$self->close_session();
|
$self->close_session();
|
||||||
$self->log(3, "finished backup for target host " . $target->{host} . " dir " . $target->{dir} . ": $count files");
|
$self->log(3, "finished backup for target host " . $target->{host} . " dir " . $target->{dir} . ": $count files");
|
||||||
$self->{counts}{objects} += $count;
|
$self->{counts}{objects} += $count;
|
||||||
|
@ -466,20 +466,16 @@ sub db_record_version {
|
||||||
}
|
}
|
||||||
my $t3 = gettimeofday();
|
my $t3 = gettimeofday();
|
||||||
$self->{times}{db_record_version_versions2} += $t3 - $t2;
|
$self->{times}{db_record_version_versions2} += $t3 - $t2;
|
||||||
$self->{dbh}->do("insert into instances(file,
|
push @{ $self->{caches}{insert_instances} },
|
||||||
file_id,
|
[
|
||||||
date, online,
|
|
||||||
session, version)
|
|
||||||
values(?,
|
|
||||||
?,
|
|
||||||
?, ?,
|
|
||||||
?, ?)",
|
|
||||||
{},
|
|
||||||
$db_f->[0]{id},
|
$db_f->[0]{id},
|
||||||
$f->{id},
|
$f->{id},
|
||||||
time(), 1,
|
time(), 1,
|
||||||
$self->{session_id}, $version_id
|
$self->{session_id}, $version_id
|
||||||
);
|
];
|
||||||
|
if (@{ $self->{caches}{insert_instances} } > 10) {
|
||||||
|
$self->flush_insert_instances();
|
||||||
|
}
|
||||||
|
|
||||||
my $t4 = gettimeofday();
|
my $t4 = gettimeofday();
|
||||||
$self->{times}{db_record_version_insert_instances} += $t4 - $t3;
|
$self->{times}{db_record_version_insert_instances} += $t4 - $t3;
|
||||||
|
@ -487,6 +483,26 @@ sub db_record_version {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub flush_insert_instances {
|
||||||
|
my ($self) = @_;
|
||||||
|
my $dbh = $self->{dbh};
|
||||||
|
|
||||||
|
if (@{ $self->{caches}{insert_instances} }) {
|
||||||
|
my $cmd = "insert into instances(file, file_id, date, online, session, version)"
|
||||||
|
. " values "
|
||||||
|
. join(", ",
|
||||||
|
map {
|
||||||
|
"("
|
||||||
|
. join(",", map { $dbh->quote($_) } @$_)
|
||||||
|
. ")"
|
||||||
|
} @{ $self->{caches}{insert_instances} }
|
||||||
|
);
|
||||||
|
$dbh->do($cmd);
|
||||||
|
}
|
||||||
|
$self->{caches}{insert_instances} = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub new_session {
|
sub new_session {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
$self->{dbh}->do("insert into sessions(start_date, prefix) values(?, ?)", {}, time(), $self->{this_backup});
|
$self->{dbh}->do("insert into sessions(start_date, prefix) values(?, ?)", {}, time(), $self->{this_backup});
|
||||||
|
@ -515,14 +531,16 @@ sub close_file_connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_last_session_id {
|
sub get_last_session {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return unless $self->{last_backup};
|
my $sessions
|
||||||
my $sessions = $self->{dbh}->selectall_arrayref("select * from sessions where prefix=?",
|
= $self->{dbh}->selectall_arrayref(
|
||||||
|
"select * from sessions where end_date is not null and prefix like ? order by end_date desc",
|
||||||
{ Slice => {} },
|
{ Slice => {} },
|
||||||
$self->{last_backup});
|
$self->{basedir} . '/%/' . $self->{target}->{host} . '/' . $self->{target}->{dir}
|
||||||
die "$self->{last_backup} not a unique prefix" unless @$sessions == 1;
|
);
|
||||||
return $sessions->[0]{id};
|
$self->{last_backup} = $sessions->[0]{prefix};
|
||||||
|
$self->{last_backup_id} = $sessions->[0]{id};
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 linkdup
|
=head2 linkdup
|
||||||
|
|
Loading…
Reference in New Issue