Add script to mount all backups

I had a simple zsh script before, but with LUKS support that would have
become more complex, so I just copied the relevant code from the backup
script.
This commit is contained in:
hjp 2018-10-13 08:01:58 +00:00
parent 86f05574e5
commit 90cdc088ed
4 changed files with 43 additions and 5 deletions

View File

@ -14,10 +14,11 @@ my $build = Module::Build->new
'Config::YAML' => 0,
},
script_files => [
'scripts/da',
'scripts/backup',
'scripts/simba_export',
'scripts/da',
'scripts/mount-all-backups',
'scripts/remove_session',
'scripts/simba_export',
],
);
$build->create_build_script;

View File

@ -4,7 +4,7 @@
"unknown"
],
"dynamic_config" : 0,
"generated_by" : "Module::Build version 0.421",
"generated_by" : "Module::Build version 0.422",
"license" : [
"perl_5"
],
@ -49,5 +49,6 @@
"http://dev.perl.org/licenses/"
]
},
"version" : "0.002"
"version" : "0.002",
"x_serialization_backend" : "JSON::PP version 2.27300_01"
}

View File

@ -4,7 +4,7 @@ author:
- unknown
build_requires: {}
dynamic_config: 0
generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.142690'
generated_by: 'Module::Build version 0.422, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@ -31,3 +31,4 @@ requires:
resources:
license: http://dev.perl.org/licenses/
version: '0.002'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'

35
scripts/mount-all-backups Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/perl
use warnings;
use strict;
use v5.10;
use File::stat;
my $st = stat("/backup/");
my $base_device = $st->dev;
my %luks_devices;
for (glob("/backup/*")) {
my $st = stat($_);
my $dir_device = $st->dev;
say STDERR ("checking $_");
if ($base_device == $dir_device) {
# not a mount point
(my $basedir = $_) =~ s{^/backup/}{};
if ($basedir =~ /^luks-(.*)/) {
my $key = $1;
for my $dev (glob("/dev/disk/by-id/*$key*")) {
my ($devbase) = $dev =~ m{([^/]+$)};
if (-e "/backup/keys/$devbase") {
say STDERR ("opening /dev/disk/by-id/$devbase on $_");
system("/sbin/cryptsetup", "open", $dev, $basedir, "--key-file", "/backup/keys/$devbase");
say STDERR ("mounting /dev/mapper/$basedir on $_");
system("/bin/mount", "-o", "nodev,noexec,nomand,nosuid", "/dev/mapper/$basedir", $_);
}
}
} elsif (-e "/dev/disk/by-id/$basedir") {
# matching device exists
say STDERR ("mounting /dev/disk/by-id/$basedir on $_");
system("/bin/mount", "-o", "nodev,noexec,nomand,nosuid", "/dev/disk/by-id/$basedir", $_);
}
}
}