Subversion Repositories zfs_utils

Rev

Rev 25 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
24 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
use FindBin;
7
use lib "$FindBin::Bin/..";
8
use ZFS_Utils qw(loadConfig shredFile mountDriveByLabel mountGeli $logFileName $displayLogsOnConsole);
9
 
10
# set the log file to be next to this script
11
$logFileName = "$FindBin::Bin/sneakernet.log";
12
# display all log messages on console in addition to the log file
13
$displayLogsOnConsole = 1;
14
 
15
my $configFileName = "$0.conf.yaml";
16
 
17
my $config = {
18
   # file created on source server to track last copyed dataset
19
   'status_file' => "$0.status",
20
   #information about source server
21
   'source_server' => {
22
      'hostname' => '', # used to see if we are on source
23
      'poolname' => '', # name of the ZFS pool to export
24
   },
25
   #information about target server
26
   'target_server' => {
27
      'hostname' => '', # used to see if we are on target
28
      'poolname' => '', # name of the ZFS pool to import
29
      # if this is set, the dataset uses GELI, so we must decrypt and
30
      # mount it first
31
      'geli' => {
32
         'keydiskname' => 'replica', # the GPT label of the key disk
33
         'keyfile' => 'geli.key', # the name of the key file on keydiskname
34
         'localKey' => 'e98c660cccdae1226550484d62caa2b72f60632ae0c607528aba1ac9e7bfbc9c', # hex representation of the local key part
35
         'target' => '/media/geli.key', # location to create the combined keyfile
36
         'poolname' => '', # name of the ZFS pool to import
37
         'diskList' => [ 
38
            '/dev/gpt/sneakernet_disk' 
39
            ], # list of disks to try to mount the dataset from
40
      }
41
   },
42
   'transport' => {
43
      # this is the GPT label of the sneakernet disk
44
      'disk_label' => 'sneakernet',
45
      # where we want to mount it
46
      'mount_point' => '/mnt/sneakernet',
47
      # amount of time to wait for the disk to appear
48
      'timeout' => 600,
49
      # if set, all files will be encrypted with this key/IV during transport
50
      'encryption' => {
51
         'key'    => '', # openssl rand 32 | xxd -p | tr -d '\n' > test.key
52
         'IV'     => '00000000000000000000000000000000',
53
      },
54
   },
55
   'datasets' => {
56
      'iscsi' => {
57
         'source' => 'storage/backup/iscsi',
58
         'target' => 'storage/backup/iscsi',
59
         'filename' => 'iscsi'
60
      },
61
      'nextcloud'  => {
62
         'source' => 'storage/backup/nextcloud',
63
         'target' => 'storage/backup/nextcloud',
64
         'filename' => 'nextcloud'
65
      },
66
      'files_share'  => {
67
         'source' => 'storage/backup/files_share',
68
         'target' => 'storage/backup/files_share',
69
         'filename' => 'files_share'
70
      },
71
   }
72
};
73
 
74
 
75
# generate a random key with
76
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
77
 
78
# If a YAML config file exists next to the script, load and merge it
79
$config = loadConfig($configFileName, $config );
80
 
81
die "Invalid config file: missing source and/or target server\n"
82
    unless (defined $config->{source_server} && defined $config->{target_server});
83
 
84
my $servername = `hostname -s`;
85
chomp $servername;
86
if ( $servername eq $config->{source_server}->{hostname} ) {
87
    print "Running as source server\n";
88
    # source server logic here
89
} elsif ( $servername eq $config->{target_server}->{hostname} ) {
90
    print "Running as target server\n";
91
    mountGeli( $config->{target_server}->{geli} ) if ( defined $config->{target_server}->{geli} );
92
} else {
93
    die "This server ($servername) is neither source nor target server as per config\n";
94
}
95
 
96
 
97
#`cat $config->{input} | openssl enc -aes-256-cbc -K $config->{key} -iv $config->{IV} > $config->{output}`;
98
 
99
# this will decrypt $config->{output} to stdout
100
#`cat $config->{output} | openssl enc -aes-256-cbc -d -K $config->{key} -iv $config->{IV} > test.out`;