Rev 25 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#! /usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/..";
use ZFS_Utils qw(loadConfig shredFile mountDriveByLabel mountGeli $logFileName $displayLogsOnConsole);
# set the log file to be next to this script
$logFileName = "$FindBin::Bin/sneakernet.log";
# display all log messages on console in addition to the log file
$displayLogsOnConsole = 1;
my $configFileName = "$0.conf.yaml";
my $config = {
# file created on source server to track last copyed dataset
'status_file' => "$0.status",
#information about source server
'source_server' => {
'hostname' => '', # used to see if we are on source
'poolname' => '', # name of the ZFS pool to export
},
#information about target server
'target_server' => {
'hostname' => '', # used to see if we are on target
'poolname' => '', # name of the ZFS pool to import
# if this is set, the dataset uses GELI, so we must decrypt and
# mount it first
'geli' => {
'keydiskname' => 'replica', # the GPT label of the key disk
'keyfile' => 'geli.key', # the name of the key file on keydiskname
'localKey' => 'e98c660cccdae1226550484d62caa2b72f60632ae0c607528aba1ac9e7bfbc9c', # hex representation of the local key part
'target' => '/media/geli.key', # location to create the combined keyfile
'poolname' => '', # name of the ZFS pool to import
'diskList' => [
'/dev/gpt/sneakernet_disk'
], # list of disks to try to mount the dataset from
}
},
'transport' => {
# this is the GPT label of the sneakernet disk
'disk_label' => 'sneakernet',
# where we want to mount it
'mount_point' => '/mnt/sneakernet',
# amount of time to wait for the disk to appear
'timeout' => 600,
# if set, all files will be encrypted with this key/IV during transport
'encryption' => {
'key' => '', # openssl rand 32 | xxd -p | tr -d '\n' > test.key
'IV' => '00000000000000000000000000000000',
},
},
'datasets' => {
'iscsi' => {
'source' => 'storage/backup/iscsi',
'target' => 'storage/backup/iscsi',
'filename' => 'iscsi'
},
'nextcloud' => {
'source' => 'storage/backup/nextcloud',
'target' => 'storage/backup/nextcloud',
'filename' => 'nextcloud'
},
'files_share' => {
'source' => 'storage/backup/files_share',
'target' => 'storage/backup/files_share',
'filename' => 'files_share'
},
}
};
# generate a random key with
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
# If a YAML config file exists next to the script, load and merge it
$config = loadConfig($configFileName, $config );
die "Invalid config file: missing source and/or target server\n"
unless (defined $config->{source_server} && defined $config->{target_server});
my $servername = `hostname -s`;
chomp $servername;
if ( $servername eq $config->{source_server}->{hostname} ) {
print "Running as source server\n";
# source server logic here
} elsif ( $servername eq $config->{target_server}->{hostname} ) {
print "Running as target server\n";
mountGeli( $config->{target_server}->{geli} ) if ( defined $config->{target_server}->{geli} );
} else {
die "This server ($servername) is neither source nor target server as per config\n";
}
#`cat $config->{input} | openssl enc -aes-256-cbc -K $config->{key} -iv $config->{IV} > $config->{output}`;
# this will decrypt $config->{output} to stdout
#`cat $config->{output} | openssl enc -aes-256-cbc -d -K $config->{key} -iv $config->{IV} > test.out`;
Generated by GNU Enscript 1.6.5.90.