Subversion Repositories zfs_utils

Rev

Rev 26 | Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26 Rev 27
Line 3... Line 3...
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
 
5
 
6
use FindBin;
6
use FindBin;
7
use lib "$FindBin::Bin/..";
7
use lib "$FindBin::Bin/..";
-
 
8
use Data::Dumper;
8
use ZFS_Utils qw(loadConfig shredFile logMsg mountDriveByLabel mountGeli $logFileName $displayLogsOnConsole);
9
use ZFS_Utils qw(loadConfig shredFile logMsg makeReplicateCommands mountDriveByLabel mountGeli runCmd $logFileName $displayLogsOnConsole);
9
 
10
 
10
# set the log file to be next to this script
11
# set the log file to be next to this script
11
$logFileName = "$FindBin::Bin/sneakernet.log";
12
$logFileName = "$FindBin::Bin/sneakernet.log";
12
# display all log messages on console in addition to the log file
13
# display all log messages on console in addition to the log file
13
$displayLogsOnConsole = 1;
14
$displayLogsOnConsole = 1;
Line 37... Line 38...
37
         'diskList' => [ 
38
         'diskList' => [ 
38
            '/dev/gpt/sneakernet_disk' 
39
            '/dev/gpt/sneakernet_disk' 
39
            ], # list of disks to try to mount the dataset from
40
            ], # list of disks to try to mount the dataset from
40
      }
41
      }
41
   },
42
   },
-
 
43
   
42
   'transport' => {
44
   'transport' => {
43
      # this is the GPT label of the sneakernet disk
45
      # this is the GPT label of the sneakernet disk
44
      'disk_label' => 'sneakernet',
46
      'disk_label' => 'sneakernet',
45
      # where we want to mount it
47
      # where we want to mount it
46
      'mount_point' => '/mnt/sneakernet',
48
      'mount_point' => '/mnt/sneakernet',
Line 56... Line 58...
56
      'iscsi' => {
58
      'iscsi' => {
57
         'source' => 'storage/backup/iscsi',
59
         'source' => 'storage/backup/iscsi',
58
         'target' => 'storage/backup/iscsi',
60
         'target' => 'storage/backup/iscsi',
59
         'filename' => 'iscsi'
61
         'filename' => 'iscsi'
60
      },
62
      },
61
      'nextcloud'  => {
-
 
62
         'source' => 'storage/backup/nextcloud',
-
 
63
         'target' => 'storage/backup/nextcloud',
-
 
64
         'filename' => 'nextcloud'
-
 
65
      },
-
 
66
      'files_share'  => {
63
      'files_share'  => {
67
         'source' => 'storage/backup/files_share',
64
         'source' => 'storage/backup/files_share',
68
         'target' => 'storage/backup/files_share',
65
         'target' => 'storage/backup/files_share',
69
         'filename' => 'files_share'
66
         'filename' => 'files_share'
70
      },
67
      },
Line 75... Line 72...
75
# generate a random key with
72
# generate a random key with
76
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
73
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
77
 
74
 
78
# If a YAML config file exists next to the script, load and merge it
75
# If a YAML config file exists next to the script, load and merge it
79
$config = loadConfig($configFileName, $config );
76
$config = loadConfig($configFileName, $config );
-
 
77
 
80
# set some defaults
78
# set some defaults
81
$config->{'status_file'} = "$0.status" unless ( defined $config->{'status_file'} );
79
$config->{'status_file'} = "$0.status" unless ( defined $config->{'status_file'} );
82
 
80
 
83
 
81
 
84
die "Invalid config file: missing source and/or target server\n"
82
die "Invalid config file: missing source and/or target server\n"
Line 108... Line 106...
108
   die;
106
   die;
109
}
107
}
110
 
108
 
111
my $newStatus = [];
109
my $newStatus = [];
112
foreach my $dataset ( sort keys %{$config->{datasets}} ) {
110
foreach my $dataset ( sort keys %{$config->{datasets}} ) {
113
   logMsg("Processing dataset '$dataset'\n");
111
   logMsg("Processing dataset '$dataset'");
114
   my $sourceList = [ runCmd( "zfs", "list", "-rt", "snap", "-H", "-o", "name", $config->{datasets}->{$dataset}->{source} ) ];
112
   my $sourceList = [ runCmd( "zfs", "list", "-rt", "snap", "-H", "-o", "name", $config->{datasets}->{$dataset}->{source} ) ];
115
   
-
 
116
   # process dataset here
113
   # process dataset here
117
   my $commands = makeReplicateCommands($sourceList, $targetList, $newStatus );
114
   my $commands = makeReplicateCommands($sourceList, $targetList, $newStatus );
118
   foreach my $cmd ( @$commands ) {
115
   foreach my $cmd ( @$commands ) {
-
 
116
      $cmd .= " > $config->{transport}->{mount_point}/" . $dataset;
119
      logMsg("Running command: $cmd\n");
117
      logMsg("Running command: $cmd");
120
      #runCmd( split( /\s+/, $cmd ) );
118
      #runCmd( split( /\s+/, $cmd ) );
121
   }
119
   }
122
}
120
}
123
 
121
 
124
1;
122
1;