summaryrefslogtreecommitdiffstats
path: root/lib/App
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-02-07 17:01:28 +0100
committerFlorian Pritz <bluewind@xinu.at>2019-02-07 17:14:35 +0100
commit4034169f9655ea6b28741067c58c0219e42365e1 (patch)
tree9a76c3c328d7420ec4dc2494889800823ab21ac2 /lib/App
parent138ba53c92dc10c1b9b9bb31448b76f9bbac0ecd (diff)
downloadApp-BorgRestore-4034169f9655ea6b28741067c58c0219e42365e1.tar.gz
App-BorgRestore-4034169f9655ea6b28741067c58c0219e42365e1.tar.xz
Support borg list --prefix option via setting
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/BorgRestore.pm2
-rw-r--r--lib/App/BorgRestore/Borg.pm8
-rw-r--r--lib/App/BorgRestore/Settings.pm11
3 files changed, 17 insertions, 4 deletions
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<App::BorgRestore>.
=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 => {