Subversion Repositories sysadmin_scripts

Rev

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

Rev 166 Rev 168
Line 136... Line 136...
136
      my $targetCommand = 'zfs receive -v ';
136
      my $targetCommand = 'zfs receive -v ';
137
      $targetCommand .= $config->{'target'}->{'dataset'};
137
      $targetCommand .= $config->{'target'}->{'dataset'};
138
      $targetCommand = "ssh $config->{target}->{server} '$sourceCommand'" if $config->{'target'}->{'server'};
138
      $targetCommand = "ssh $config->{target}->{server} '$sourceCommand'" if $config->{'target'}->{'server'};
139
      push @return, $sourceCommand . ' | ' . $targetCommand;
139
      push @return, $sourceCommand . ' | ' . $targetCommand;
140
   } else {
140
   } else {
141
      push @return, '# No action, all synced';
141
      push @return, '# Nothing new to sync';
142
   }
142
   }
143
   # now, check for snapshots to remove
143
   # now, check for snapshots to remove
144
   if ( $config->{'actions'}->{'deleteTarget'} ) {
144
   if ( $config->{'actions'}->{'deleteTarget'} ) {
145
      for ( my $i = 0; $i < @{$config->{'actions'}->{'deleteTarget'}}; $i++ ) {
145
      my $delete = $config->{'actions'}->{'deleteTarget'};
-
 
146
      foreach my $ds ( @$delete ) {
146
         push @return, 'zfs destroy -r ' . {$config->{'actions'}->{'deleteTarget'}}->[$i];
147
         push @return, "zfs destroy -r $config->{target}->{'dataset'}\@$ds";
147
      }
148
      }
-
 
149
   } else {
-
 
150
      push @return, "# No old snapshots to be removed";
148
   }
151
   }
149
 
-
 
150
   return \@return;
152
   return \@return;
151
}
153
}
152
   
154
   
153
 
155
 
154
 
156
 
Line 156... Line 158...
156
   my $config = shift;
158
   my $config = shift;
157
   my $return;
159
   my $return;
158
   my $allMatch;
160
   my $allMatch;
159
   my $lastMatch;
161
   my $lastMatch;
160
   foreach my $dataset ( sort keys %{$config->{'source'}->{'snapshots'}} ) {
162
   foreach my $dataset ( sort keys %{$config->{'source'}->{'snapshots'}} ) {
161
      next unless $dataset;
163
      next unless exists $config->{'source'}->{'snapshots'}->{$dataset};
162
      die "No matching target for $dataset\n" unless $config->{'target'}->{'snapshots'}->{$dataset};
164
      die "No matching target for $dataset\n" unless $config->{'target'}->{'snapshots'}->{$dataset};
163
      $return->{$dataset} = &diffSnaps( 
165
      $return->{$dataset} = &diffSnaps( 
164
         $config->{'source'}->{'snapshots'}->{$dataset}->{'snaps'},
166
         $config->{'source'}->{'snapshots'}->{$dataset}->{'snaps'},
165
         $config->{'target'}->{'snapshots'}->{$dataset}->{'snaps'}
167
         $config->{'target'}->{'snapshots'}->{$dataset}->{'snaps'}
166
      );
168
      );
167
      $allMatch = $return->{$dataset} unless $allMatch;
169
      $allMatch = $return->{$dataset} unless $allMatch;
-
 
170
#      die Dumper( $allMatch ) . "\n";
168
      next;
171
      next;
169
      unless ( 
172
      unless ( 
170
         &arrayEquals( $return->{'allMatch'}->{'deleteTarget'}, $return->{$dataset}->{'deleteTarget'} ) &&
173
         &arrayEquals( $return->{'allMatch'}->{'deleteTarget'}, $return->{$dataset}->{'deleteTarget'} ) &&
171
         &arrayEquals( $return->{'allMatch'}->{'addTarget'},    $return->{$dataset}->{'addTarget'} )
174
         &arrayEquals( $return->{'allMatch'}->{'addTarget'},    $return->{$dataset}->{'addTarget'} )
172
         ) {
175
         ) {
Line 175... Line 178...
175
      }
178
      }
176
   }
179
   }
177
   #print Dumper( $allMatch );
180
   #print Dumper( $allMatch );
178
   $return->{'lastMatch'} = $allMatch->{'lastMatch'};
181
   $return->{'lastMatch'} = $allMatch->{'lastMatch'};
179
   $return->{'finalSync'} = $allMatch->{'finalSync'};
182
   $return->{'finalSync'} = $allMatch->{'finalSync'};
-
 
183
#   die Dumper( $allMatch->{'deleteTarget'} ) . "\n" ;
-
 
184
   $return->{'deleteTarget'} = $allMatch->{'deleteTarget'};
-
 
185
#   print Dumper( $return ) . "\n"; die;
180
   return $return;
186
   return $return;
181
   #print Dumper( $return ) . "\n"; die;
187
   #print Dumper( $return ) . "\n"; die;
182
}
188
}
183
 
189
 
184
$config->{'source'} = &parseDataSet( $source );
190
$config->{'source'} = &parseDataSet( $source );
185
$config->{'target'} = &parseDataSet( $target );
191
$config->{'target'} = &parseDataSet( $target );
186
 
192
 
187
# both source and target can not have a server portion; one must be local
193
# both source and target can not have a server portion; one must be local
188
die "Source and Target can not both be remote\n" if $config->{'source'}->{'server'} && $config->{'target'}->{'server'};
194
die "Source and Target can not both be remote\n" if $config->{'source'}->{'server'} && $config->{'target'}->{'server'};
189
 
195
 
190
#die Dumper( $config );
-
 
191
 
-
 
192
$config->{'source'}->{'snapshots'} = &getSnaps( $config->{'source'}, $config->{'pattern'} );
196
$config->{'source'}->{'snapshots'} = &getSnaps( $config->{'source'}, $config->{'pattern'} );
193
$config->{'target'}->{'snapshots'} = &getSnaps( $config->{'target'}, $config->{'pattern'} );
197
$config->{'target'}->{'snapshots'} = &getSnaps( $config->{'target'}, $config->{'pattern'} );
194
 
198
 
195
$config->{'actions'} = &calculate( $config );
199
$config->{'actions'} = &calculate( $config );
196
 
200
 
-
 
201
#print Dumper( $config ); die;
-
 
202
 
197
my $commands = &createCommands( $config );
203
my $commands = &createCommands( $config );
198
for ( my $i = 0; $i < @{$commands}; $i++ ) {
204
for ( my $i = 0; $i < @{$commands}; $i++ ) {
199
   print $$commands[$i] . "\n";
205
   print "$$commands[$i]\n";
-
 
206
   #qx/$$commands[$i]/;
200
}
207
}
201
 
208
 
202
#print Dumper( $config );
209
#print Dumper( $config );
203
 
210
 
204
1;
211
1;
205
 
212