App-BorgRestore
view release on metacpan or search on metacpan
lib/App/BorgRestore.pm view on Meta::CPAN
# one
my $remove_archives = $self->get_missing_items($borg_archives, $existing_archives);
if (@$remove_archives) {
for my $archive (@$remove_archives) {
$log->infof("Removing archive %s", $archive);
$self->{deps}->{db}->begin_work;
$self->{deps}->{db}->remove_archive($archive);
$self->{deps}->{db}->commit;
$self->{deps}->{db}->vacuum;
$self->{deps}->{db}->verify_cache_fill_rate_ok();
}
my $end = Time::HiRes::gettimeofday();
$log->debugf("Removing archives finished after: %.5fs", $end - $start);
}
}
method _handle_added_archives($borg_archives) {
my $archives = $self->{deps}->{db}->get_archive_names();
my $add_archives = $self->get_missing_items($archives, $borg_archives);
lib/App/BorgRestore.pm view on Meta::CPAN
#$log->debugf("Adding path %s with time %s", $+{path}, $time);
$lookuptable->add_path($+{path}, $time);
}
});
my $borg_time = Time::HiRes::gettimeofday;
$lookuptable->save_nodes();
$self->{deps}->{db}->commit;
$self->{deps}->{db}->vacuum;
$self->{deps}->{db}->verify_cache_fill_rate_ok();
my $end = Time::HiRes::gettimeofday();
$log->debugf("Adding archive finished after: %.5fs (parsing borg output took %.5fs)", $end - $start, $borg_time - $start);
}
}
=head3 update_cache
$app->update_cache();
lib/App/BorgRestore.pm view on Meta::CPAN
$log->debug("Updating cache if required");
my $borg_archives = $self->{deps}->{borg}->borg_list();
# write operations benefit from the large cache so set the cache size here
$self->{deps}->{db}->set_cache_size();
$self->_handle_removed_archives($borg_archives);
$self->_handle_added_archives($borg_archives);
$log->debugf("DB contains information for %d archives in %d rows", scalar(@{$self->{deps}->{db}->get_archive_names()}), $self->{deps}->{db}->get_archive_row_count());
$self->{deps}->{db}->verify_cache_fill_rate_ok();
}
1;
__END__
=head1 LICENSE
Copyright (C) 2016-2018 Florian Pritz E<lt>bluewind@xinu.atE<gt>
lib/App/BorgRestore/DB.pm view on Meta::CPAN
}
method begin_work() {
$self->{dbh}->begin_work();
}
method commit() {
$self->{dbh}->commit();
}
method verify_cache_fill_rate_ok() {
my $used = $self->{dbh}->sqlite_db_status()->{cache_used}->{current};
$log->debugf("sqlite page cache usage: %s", format_bytes($used, si=>1));
if ($used > $self->{cache_size} * 1024 * 0.95) {
$log->debugf("sqlite cache usage is %s of %s", format_bytes($used, si=>1), format_bytes($self->{cache_size} * 1024, si => 1));
$log->debug("Consider increasing the sqlite cache if you notice performance issues (see documentation of App::BorgRestore::Settings)");
}
}
method search_path($pattern) {
$log->debugf("Preparing path search for pattern '%s'", $pattern);
t/handle_added_archives.t view on Meta::CPAN
use Log::Any::Adapter ('TAP');
use POSIX qw(tzset);
use Test::Differences;
use Test::MockObject;
use Test::More;
use App::BorgRestore;
# Only log calls to $db->add_path
my $db = Test::MockObject->new();
$db->set_true(qw(add_path -begin_work -commit -vacuum -add_archive_name -verify_cache_fill_rate_ok));
$db->mock('-get_archive_id', sub {return 'prefix-archive-1' if $_[1] eq 'archive-1';});
$db->mock('-get_archive_names', sub {return []});
$ENV{TZ} = 'UTC';
tzset;
my $borg = Test::MockObject->new();
$borg->set_list('borg_list', ['archive-1']);
$borg->mock('list_archive', sub {
my ($self, $archive, $cb) = @_;
( run in 0.255 second using v1.01-cache-2.11-cpan-73692580452 )