summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-04-02 23:58:04 +0200
committerFlorian Pritz <bluewind@xinu.at>2017-04-02 23:58:45 +0200
commit686623ab687cfd4aaa5b4c156faf65ee75ad4000 (patch)
tree3e01a536d8196f9aaa3e7da21bc2453c5c3b97dc /lib
parentd919cb733de7622835aa6148ed939051d67cb64f (diff)
downloadApp-BorgRestore-686623ab687cfd4aaa5b4c156faf65ee75ad4000.tar.gz
App-BorgRestore-686623ab687cfd4aaa5b4c156faf65ee75ad4000.tar.xz
Make sqlite cache size configurable
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/App/BorgRestore.pm3
-rw-r--r--lib/App/BorgRestore/DB.pm8
-rw-r--r--lib/App/BorgRestore/Settings.pm10
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index 4047b2c..9c236e3 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -93,9 +93,10 @@ sub new {
bless $self, $class;
my $db_path = App::BorgRestore::Settings::get_db_path();
+ my $cache_size = $App::BorgRestore::Settings::sqlite_cache_size;
$self->{borg} = $deps->{borg} // App::BorgRestore::Borg->new($App::BorgRestore::Settings::borg_repo);
- $self->{db} = $deps->{db} // App::BorgRestore::DB->new($db_path);
+ $self->{db} = $deps->{db} // App::BorgRestore::DB->new($db_path, $cache_size);
return $self;
}
diff --git a/lib/App/BorgRestore/DB.pm b/lib/App/BorgRestore/DB.pm
index a7c5916..e01aee2 100644
--- a/lib/App/BorgRestore/DB.pm
+++ b/lib/App/BorgRestore/DB.pm
@@ -12,15 +12,16 @@ use Log::Any qw($log);
sub new {
my $class = shift;
my $db_path = shift;
+ my $cache_size = shift;
my $self = {};
bless $self, $class;
if (! -f $db_path) {
- my $db = $self->open_db($db_path);
+ my $db = $self->open_db($db_path, $cache_size);
$self->{db}->initialize_db();
} else {
- $self->_open_db($db_path);
+ $self->_open_db($db_path, $cache_size);
}
return $self;
@@ -29,10 +30,11 @@ sub new {
sub _open_db {
my $self = shift;
my $dbfile = shift;
+ my $cache_size = shift;
$log->debugf("Opening database at %s", $dbfile);
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$dbfile","","", {RaiseError => 1, Taint => 1});
- $self->{dbh}->do("PRAGMA cache_size=-1024000");
+ $self->{dbh}->do("PRAGMA cache_size=-".$cache_size);
$self->{dbh}->do("PRAGMA strict=ON");
}
diff --git a/lib/App/BorgRestore/Settings.pm b/lib/App/BorgRestore/Settings.pm
index 564d0f8..eba5e9c 100644
--- a/lib/App/BorgRestore/Settings.pm
+++ b/lib/App/BorgRestore/Settings.pm
@@ -61,6 +61,14 @@ same string. The first regex that matches for a given file is used. This
setting only affects lookups, it does not affect the creation of the database
with --update-database.
+=item C<$sqlite_cache_size>
+
+Default: 102400
+
+The size of the in-memory cache of sqlite in kibibytes. This should be large
+enough to fit the database so that adding new backup data does not need to use
+the disk too much.
+
=back
=head2 Example Configuration
@@ -73,6 +81,7 @@ with --update-database.
{regex => "^/boot", replacement => ""},
{regex => "^/", replacement => "mnt/snapshots/root/"},
);
+ $sqlite_cache_size = 2097152;
=head1 LICENSE
@@ -86,6 +95,7 @@ our $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $EN
our @backup_prefixes = (
{regex => "^/", replacement => ""},
);
+our $sqlite_cache_size = 102400;
my @configfiles = (
sprintf("%s/borg-restore.cfg", $ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config"),