From 4034169f9655ea6b28741067c58c0219e42365e1 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 7 Feb 2019 17:01:28 +0100 Subject: Support borg list --prefix option via setting Signed-off-by: Florian Pritz --- Changes | 1 + lib/App/BorgRestore.pm | 2 +- lib/App/BorgRestore/Borg.pm | 8 +++++--- lib/App/BorgRestore/Settings.pm | 11 +++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index c90d245..807706c 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Perl extension App-BorgRestore {{$NEXT}} + - Support borg list's --prefix option via $borg_prefix setting - Properly handle cases where the DB is empty after removal of archive information diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index 753567e..1e923c5 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -93,7 +93,7 @@ method new($class: $deps = {}) { my $config = $deps->{settings}->get_config(); - $deps->{borg} //= App::BorgRestore::Borg->new($config->{borg}->{repo}); + $deps->{borg} //= App::BorgRestore::Borg->new(@{$config->{borg}}{qw(repo backup_prefix)}); $deps->{db} //= App::BorgRestore::DB->new($config->{cache}->{database_path}, $config->{cache}->{sqlite_memory_cache_size}); return $class->new_no_defaults($deps, $config); diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm index 62555fa..def6b9c 100644 --- a/lib/App/BorgRestore/Borg.pm +++ b/lib/App/BorgRestore/Borg.pm @@ -24,11 +24,12 @@ App::BorgRestore::Borg abstracts borg commands used by L. =cut -method new($class: $borg_repo) { +method new($class: $borg_repo, $backup_prefix) { my $self = {}; bless $self, $class; $self->{borg_repo} = $borg_repo; + $self->{backup_prefix} = $backup_prefix; $self->{borg_version} = $self->borg_version(); @@ -52,17 +53,18 @@ method borg_version() { method borg_list() { my @archives; + my $backup_prefix = $self->{backup_prefix}; if (Version::Compare::version_compare($self->{borg_version}, "1.1") >= 0) { $log->debug("Getting archive list via json"); - run [qw(borg list --json), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; + run [qw(borg list --prefix), $backup_prefix, qw(--json), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; my $json = decode_json($output); for my $archive (@{$json->{archives}}) { push @archives, $archive->{archive}; } } else { $log->debug("Getting archive list"); - run [qw(borg list), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; + run [qw(borg list --prefix), $backup_prefix, $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n"; for (split/^/, $output) { if (m/^([^\s]+)\s/) { diff --git a/lib/App/BorgRestore/Settings.pm b/lib/App/BorgRestore/Settings.pm index 9ef03d7..bc4fbd0 100644 --- a/lib/App/BorgRestore/Settings.pm +++ b/lib/App/BorgRestore/Settings.pm @@ -47,6 +47,14 @@ This specifies the URL to the borg repo as used in other borg commands. If you use the $BORG_REPO environment variable set this to an empty string. Default: "backup:borg-".hostname; +=item C<$backup_prefix> + +This specifies that only archives with the prefix should be considered. For +example, if you back up multiple things (file system and database) into +differntly named archives (fs-* and db-*), this can be used to only consider +file system archives to keep the database size small. In the example you'd set +the setting to "fs-". An empty string considers all archives. Default: "" + =item C<$cache_path_base> This defaults to "C<$XDG_CACHE_HOME>/borg-restore.pl". It contains the lookup database. @@ -97,6 +105,7 @@ New in version 3.2.0. Deprecated in v3.2.0 for future removal possibly in v4.0.0 =head2 Example Configuration $borg_repo = "/path/to/repo"; + $backup_prefix = ""; $cache_path_base = "/mnt/somewhere/borg-restore.pl-cache"; @backup_prefixes = ( {regex => "^/home/", replacement => "mnt/snapshots/home/"}, @@ -129,6 +138,7 @@ our @backup_prefixes = ( ); our $sqlite_cache_size = 102400; our $prepare_data_in_memory = 0; +our $backup_prefix = ""; method new_no_defaults($class: $deps = {}) { my $self = {}; @@ -157,6 +167,7 @@ method get_config() { return { borg => { repo => $borg_repo, + backup_prefix => $backup_prefix, path_prefixes => [@backup_prefixes], }, cache => { -- cgit v1.2.3-24-g4f1b