summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-08-14 10:57:21 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-08-14 10:57:21 +0200
commitbcc838d24280a38dcede58773860275d98e744c5 (patch)
tree39f3d50c84f025ba4b25359b0c66ca50baddc509
parent44578ace80a974631b4becddba997affac625765 (diff)
downloadbin-bcc838d24280a38dcede58773860275d98e744c5.tar.gz
bin-bcc838d24280a38dcede58773860275d98e744c5.tar.xz
borg-restore.pl: WIP
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xborg-restore.pl81
1 files changed, 55 insertions, 26 deletions
diff --git a/borg-restore.pl b/borg-restore.pl
index 95bb75d..d9fc8e8 100755
--- a/borg-restore.pl
+++ b/borg-restore.pl
@@ -17,20 +17,53 @@ Also allows to specify a time for automatic selection of the backup that has to
be restored. If a time is specified, the script will automatically select the
newest backup that is at least as old as the time value that is passed.
-Backups are restored to their original destination if that destination does not
+Backups are restored to their original destination if no --destination is given.
+if that destination does not
exist. If restoration should be attempted to an existing destination, the
destination has to be passed as an argument.
=cut
+=head1 OPTIONS
+
+=item C<--help>, C<-h>
+
+Show help message
+
+=back
+
+=item C<--debug>
+
+Enable debug messages.
+
+=back
+
+=item C<--update-cache>, C<-u>
+
+Update the lookup database. You should run this after creating or removing a backup.
+
+=back
+
+=item C<--destination>, C<-d>
+
+Restore the backup to 'path' instead of its original location. The destination
+either has to be a directory or missing in which case it will be created. The
+backup will then be restored into the directory with its original file or
+directory name.
+
+=back
+
=head1 SYNOPSIS
-borg-restore.pl [options] <path> [[<time spec>] <destination>]
+borg-restore.pl [options] <path>
Options:
- --help, -h short help message
- --debug show debug messages
- --update-cache, -u update cache files
+ --help, -h short help message
+ --debug show debug messages
+ --update-cache, -u update cache files
+ --destination, -d <path> Restore backup to directory <path>
+ --time, -t <timespec> Automatically find newest backup that is at least
+ <time spec> old
Time spec:
Select the newest backup that is at least <time spec> old.
@@ -363,7 +396,7 @@ sub sanitize_db_data {
if (defined($item)) {
push @ret, $item + 0;
} else {
- push @ret, undef;
+ push @ret, -1;
}
}
@@ -519,7 +552,7 @@ sub get_mtime_from_lookuptable {
for my $component (@components) {
$node = $$node[0]->{$component};
if (!defined($node)) {
- return undef;
+ return -1;
}
}
return $$node[1];
@@ -529,8 +562,8 @@ sub clean_db {
my $archives = shift;
while (my ($path, $data) = each %db) {
- # check if data is empty or all fields in data are undef
- if (!@$data || all { !defined($_) } @$data) {
+ # check if data is empty or all fields in data are -1
+ if (!@$data || all { $_ != -1 } @$data) {
debug("Deleting path because it's not part of any archive: ", $path);
delete $db{$path};
}
@@ -555,7 +588,7 @@ sub main {
$ENV{PATH} = untaint($ENV{PATH}, qr(.*));
Getopt::Long::Configure ("bundling");
- GetOptions(\%opts, "help|h", "debug", "update-cache|u") or pod2usage(2);
+ GetOptions(\%opts, "help|h", "debug", "update-cache|u", "destination|d=s", "time|t=s") or pod2usage(2);
pod2usage(0) if $opts{help};
if ($opts{"update-cache"}) {
@@ -571,24 +604,20 @@ sub main {
my $timespec;
my $destination;
- if (@ARGV == 1) {
- $path = $ARGV[0];
- } elsif (@ARGV == 2) {
- $path = $ARGV[0];
- $destination = $ARGV[1];
- } elsif (@ARGV == 3) {
- $path = $ARGV[0];
- $timespec = $ARGV[1];
- $destination = $ARGV[2];
+ $path = $ARGV[0];
+
+ if (defined($opts{destination})) {
+ $destination = $opts{destination};
+ }
+
+ if (defined($opts{time})) {
+ $timespec = $opts{time};
}
- # TODO only accept one source path
- # <source path> [time spec] <destination path>
- # handle destination path similar to rsync
- # / at the end -> replace directory
- # no / -> restore into directory
- #
- # time spec: take most recent backup that is at least $timespec old
+ if (@ARGV > 1) {
+ say STDERR "Error: Too many arguments";
+ exit(1);
+ }
my $abs_path = abs_path($path);
if (!defined($destination)) {