Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Change the log location to be a variable
- #Change the log location to include a date/time
- #!/usr/bin/perl
- use strict;
- use warnings;
- use REST::Client;
- use MIME::Base64;
- use JSON;
- use Data::Dumper;
- use Getopt::Std;
- # NOTE: THIS SCRIPT REQUIRES XTREMIO VERSION 4.0.2 is later
- #
- # The snapshot set name is renamed as a part of the refresh operation, so
- # a temporary name is used, and then the set is renamed back to the
- # original name.
- #
- # Scott Howard, scott.howard@emc.com
- # Daniel Pum, daniel.pum@emc.com
- my %opts;
- getopts('v', \%opts);
- my $verbose=$opts{v};
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
- my $CLUSTER="cluster";
- my @VGS=("prdvg", "prdjrnvg", "prdinstvg");
- # Assumption is that each CG is VG-cg
- # Assumption is that each SS is VG-ssro and VG-ssrw
- my $XMSUSER="username";
- my $XMSPASS="password";
- my $XMS="hostname-or-IP";
- my $DELETEDELAY=60;
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
- #
- # Check the response from all API calls, and exit if they fail
- #
- sub checkerr($) {
- my ($cl) = @_;
- my $respcode=$cl->responseCode();
- return 0 if ($respcode>=200 && $respcode <300);f
- # Error message is normally JSON, but sometimes it isnt...
- my $msg = $cl->responseContent();
- if ($msg =~ /^{/) {
- $msg = from_json($msg)->{message};
- }
- print STDERR "Error - $msg (response code $respcode)\n";
- exit(2);
- }
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
- open(my $fh, '>', 'epic-snapshot-script.log') or die "Could not write to epic-snapshot-script.log\n";
- ########
- # Setup the REST API connection to XMS
- ########
- $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
- my $client = REST::Client->new();
- my $headers = {Authorization => "Basic ".encode_base64($XMSUSER.":".$XMSPASS), "Content-Type" => 'application/json'};
- ########
- # Freeze Cache
- ########
- print $fh "Freeze Cache\n";
- #my $result = `ssh -l EPICUSER EPICHOST /epic/prd/bin/instfreeze`;
- my $result = "\n";
- print $fh $result . "\n\n";
- ########
- # Freeze filesystems (only for AIX)
- ########
- print $fh "Freeze JFS filesystems\n";
- #$result = `ssh -l root EPICHOST /epic/prd/bin/jfs-freeze-script`;
- print $fh $result . "\n\n";
- ########
- # Refresh the RO snapshot set, WITHOUT the no-backup option
- # Loop through all the volume groups - one consistency group per host volume group
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRO = $_ . "-ssro";
- my $SSRONEW = $_ . "-ssro-new";
- my $SSROOLD = $_ . "-ssro-old";
- print $fh "Refresh RO snapshot set $SSRO from consistency group $CGNAME\n";
- my %body= ('cluster-id' => $CLUSTER,
- 'from-consistency-group-id' => $CGNAME,
- 'to-snapshot-set-id' => $SSRO,
- 'snapshot-set-name' => $SSRONEW,
- );
- $client->POST("https://$XMS/api/json/v2/types/snapshots", encode_json(\%body), $headers);
- checkerr($client);
- my $resp = from_json($client->responseContent());
- print $fh Dumper($resp) . "\n\n";
- }
- ########
- # Thaw filesystems (only for AIX)
- ########
- print $fh "Thaw JFS filesystems\n";
- #$result = `ssh -l root EPICHOST /epic/prd/bin/jfs-thaw-script`;
- print $fh $result . "\n\n";
- ########
- # Thaw Cache
- ########
- print $fh "Thaw Cache\n";
- #$result = `ssh -l EPICUSER EPICHOST /epic/prd/bin/instthaw`;
- print $fh $result . "\n\n";
- ########
- # Rotate RO snapshots sets. Current becomes old, new becomes current
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRO = $_ . "-ssro";
- my $SSRONEW = $_ . "-ssro-new";
- my $SSROOLD = $_ . "-ssro-old";
- print $fh "Rename snapshot set $SSRO to $SSROOLD\n";
- my %body= ('new-name' => $SSROOLD,);
- $client->PUT("https://$XMS/api/json/v2/types/snapshot-sets?name=$SSRO&cluster-name=$CLUSTER", encode_json(\%body), $headers);
- checkerr($client);
- print $fh "Rename snapshot set $SSRONEW to $SSRO\n";
- %body= ('new-name' => $SSRO,);
- $client->PUT("https://$XMS/api/json/v2/types/snapshot-sets?name=$SSRONEW&cluster-name=$CLUSTER", encode_json(\%body), $headers);
- checkerr($client);
- }
- ########
- # Refresh the RW snapshot set from the RO snapshot set, WITHOUT the no-backup option
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRO = $_ . "-ssro";
- my $SSRW = $_ . "-ssrw";
- my $SSRWNEW = $_ . "-ssrw-new";
- my $SSRWOLD = $_ . "-ssrw-old";
- print $fh "Refresh RW snapshot set $SSRW from snapshot set $SSRO\n";
- my %body= ('cluster-id' => $CLUSTER,
- 'from-snapshot-set-id' => $SSRO,
- 'to-snapshot-set-id' => $SSRW,
- 'snapshot-set-name' => $SSRWNEW,
- );
- $client->POST("https://$XMS/api/json/v2/types/snapshots", encode_json(\%body), $headers);
- checkerr($client);
- my $resp = from_json($client->responseContent());
- print $fh Dumper($resp) . "\n\n";
- }
- ########
- # Rotate RW snapshots sets. Current becomes old, new becomes current
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRW = $_ . "-ssrw";
- my $SSRWNEW = $_ . "-ssrw-new";
- my $SSRWOLD = $_ . "-ssrw-old";
- print $fh "Rename snapshot set $SSRW to $SSRWOLD\n";
- my %body= ('new-name' => $SSRWOLD,);
- $client->PUT("https://$XMS/api/json/v2/types/snapshot-sets?name=$SSRW&cluster-name=$CLUSTER", encode_json(\%body), $headers);
- checkerr($client);
- print $fh "Rename snapshot set $SSRWNEW to $SSRW\n";
- %body= ('new-name' => $SSRW,);
- $client->PUT("https://$XMS/api/json/v2/types/snapshot-sets?name=$SSRWNEW&cluster-name=$CLUSTER", encode_json(\%body), $headers);
- checkerr($client);
- }
- ########
- # Get a list of RO snapshot volumes to delete
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRO = $_ . "-ssro";
- my $SSRONEW = $_ . "-ssro-new";
- my $SSROOLD = $_ . "-ssro-old";
- print $fh "Get list of RO snapshot volumes to delete\n";
- $client->GET("https://${XMS}/api/json/v2/types/snapshot-sets?name=$SSROOLD&cluster-name=$CLUSTER&prop=vol-list", $headers);
- checkerr($client);
- my $resp = from_json($client->responseContent());
- print $fh Dumper($resp) . "\n\n";
- my $volumes = $resp->{'content'}{'vol-list'};
- foreach my $volume (@$volumes){
- my ($id, $name, $number) = @$volume;
- print $fh "Deleting snapshot volume $name\n";
- $client->DELETE("https://$XMS/api/json/v2/types/volumes?name=$name&cluster-name=$CLUSTER", $headers);
- checkerr($client);
- sleep $DELETEDELAY;
- }
- }
- ########
- # Get a list of RW snapshot volumes to delete
- ########
- foreach ( @VGS ) {
- my $CGNAME = $_ . "-cg";
- my $SSRW = $_ . "-ssrw";
- my $SSRWNEW = $_ . "-ssrw-new";
- my $SSRWOLD = $_ . "-ssrw-old";
- print $fh "Get list of RW snapshot volumes to delete\n";
- $client->GET("https://${XMS}/api/json/v2/types/snapshot-sets?name=$SSRWOLD&cluster-name=$CLUSTER&prop=vol-list", $headers);
- checkerr($client);
- my $resp = from_json($client->responseContent());
- print $fh Dumper($resp) . "\n\n";
- my $volumes = $resp->{'content'}{'vol-list'};
- foreach my $volume (@$volumes){
- my ($id, $name, $number) = @$volume;
- print $fh "Deleting snapshot volume $name\n";
- $client->DELETE("https://$XMS/api/json/v2/types/volumes?name=$name&cluster-name=$CLUSTER", $headers);
- checkerr($client);
- sleep $DELETEDELAY;
- }
- }
- close $fh;
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement