Subversion Repositories zfs_utils

Rev

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

Rev 24 Rev 25
Line 75... Line 75...
75
# generate a random key with
75
# generate a random key with
76
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
76
# openssl rand 32 | xxd -p | tr -d '\n' > test.key
77
 
77
 
78
# If a YAML config file exists next to the script, load and merge it
78
# If a YAML config file exists next to the script, load and merge it
79
$config = loadConfig($configFileName, $config );
79
$config = loadConfig($configFileName, $config );
-
 
80
# set some defaults
-
 
81
$config->{'status_file'} = "$0.status" unless ( defined $config->{'status_file'} );
-
 
82
 
80
 
83
 
81
die "Invalid config file: missing source and/or target server\n"
84
die "Invalid config file: missing source and/or target server\n"
82
    unless (defined $config->{source_server} && defined $config->{target_server});
85
    unless (defined $config->{source_server} && defined $config->{target_server});
83
 
86
 
84
my $servername = `hostname -s`;
87
my $servername = `hostname -s`;
85
chomp $servername;
88
chomp $servername;
86
if ( $servername eq $config->{source_server}->{hostname} ) {
89
if ( $servername eq $config->{source_server}->{hostname} ) {
87
    print "Running as source server\n";
90
    logMsg "Running as source server\n";
88
    # source server logic here
91
    # source server logic here
89
} elsif ( $servername eq $config->{target_server}->{hostname} ) {
92
} elsif ( $servername eq $config->{target_server}->{hostname} ) {
90
    print "Running as target server\n";
93
    logMsg "Running as target server\n";
91
    mountGeli( $config->{target_server}->{geli} ) if ( defined $config->{target_server}->{geli} );
94
    mountGeli( $config->{target_server}->{geli} ) if ( defined $config->{target_server}->{geli} );
92
} else {
95
} else {
93
    die "This server ($servername) is neither source nor target server as per config\n";
96
    logMsg "This server ($servername) is neither source nor target server as per config\n";
-
 
97
    die;
-
 
98
}
-
 
99
 
-
 
100
# read in history/status file
-
 
101
my $targetList = [];
-
 
102
if ( -e $config->{status_file} && open my $fh, '<', $config->{status_file} ) {
-
 
103
   chomp( my @lines = <$fh> );
-
 
104
   $targetList = \@lines;
-
 
105
   close $fh;
-
 
106
} else {
-
 
107
   logMsg("Error: could not read status file '$config->{status_file}': $!");
-
 
108
   die;
94
}
109
}
95
 
110
 
-
 
111
my $newStatus = [];
-
 
112
foreach my $dataset ( sort keys %{$config->{datasets}} ) {
-
 
113
   logMsg("Processing dataset '$dataset'\n");
-
 
114
   my $sourceList = [ runCmd( "zfs", "list", "-rt", "snap", "-H", "-o", "name", $config->{datasets}->{$dataset}->{source} ) ];
-
 
115
   
-
 
116
   # process dataset here
-
 
117
   my $commands = makeReplicateCommands($sourceList, $targetList, $newStatus );
-
 
118
   foreach my $cmd ( @$commands ) {
-
 
119
      logMsg("Running command: $cmd\n");
-
 
120
      #runCmd( split( /\s+/, $cmd ) );
-
 
121
   }
-
 
122
}
-
 
123
 
-
 
124
1;
-
 
125
 
96
 
126
 
97
#`cat $config->{input} | openssl enc -aes-256-cbc -K $config->{key} -iv $config->{IV} > $config->{output}`;
127
#`cat $config->{input} | openssl enc -aes-256-cbc -K $config->{key} -iv $config->{IV} > $config->{output}`;
98
 
128
 
99
# this will decrypt $config->{output} to stdout
129
# 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`;
130
#`cat $config->{output} | openssl enc -aes-256-cbc -d -K $config->{key} -iv $config->{IV} > test.out`;