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:
parent
86f05574e5
commit
90cdc088ed
5
Build.PL
5
Build.PL
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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", $_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue