#!/local/os/bin/perl -w # by Ted Zlatanov # please send back suggestions and improvements use strict; use Data::Dumper; use AppConfig qw/:expand :argcount/; my $config = AppConfig->new(); $config->define( 'HELP' => { ARGCOUNT => ARGCOUNT_NONE, DEFAULT => 0, ALIAS => 'H'}, 'VERBOSE' => { ARGCOUNT => ARGCOUNT_NONE, DEFAULT => 0, ALIAS => 'V'}, 'OVERWRITE_MODE' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => 'Y', ALIAS => 'I'}, 'SERVER' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => 'lisa',}, 'WHERETO_DIR' => { ARGCOUNT => ARGCOUNT_ONE, ALIAS => 'T'}, 'PREFIX' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => '/backups/spl-procom0', ALIAS => 'P'}, 'SKIP' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => 0, ALIAS => 'S'}, 'N' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => 9999999999,}, 'SETS' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => 1,}, 'DATE' => { ARGCOUNT => ARGCOUNT_ONE, DEFAULT => '03/12/2003', ALIAS => 'A'}, 'REVERSE' => { ARGCOUNT => ARGCOUNT_NONE, DEFAULT => 0, ALIAS => 'R'}, ); die "Invalid options passed to $0, ignoring" unless $config->args(); if ($config->HELP()) { print <PREFIX; my $where = shift @ARGV || die "You must run $0 with a directory name to restore"; my $where_to = $config->WHERETO_DIR() || die "You must provide the -whereto_dir parameter"; my $when = $config->DATE(); my $skip = $config->SKIP(); my $n = $config->N(); my $overwrite = $config->OVERWRITE_MODE(); my $server = $config->SERVER() || die "You must provide a valid server name to -server" my $direction = ($config->REVERSE()) ? '>' : '<'; my $mm_command = "/usr/sbin/nsr/mminfo -q 'name=$prefix$where,incomplete=false,savetime$direction$when' -r 'ssid,cloneid'"; print "Getting save set IDs of directory $where as of $when\n"; print "Command [$mm_command]\n"; my @saves = `$mm_command`; my @sets = (); my @unsorted_sets = (); my %seen_sets = (); foreach my $line (@saves) { next unless $line =~ m/(\d+)\s+(\d+)/; next if exists $seen_sets{$1}; # skip known save sets my $setline = "$1/$2"; push @unsorted_sets, { ssid => $1, time => $2, line => $setline }; } foreach my $set (sort { $a->{time} <=> $b->{time} } @unsorted_sets) { # printf "Got sorted set %s\n", $set->{line} # if $config->VERBOSE(); push @sets, $set; $seen_sets{$set->{ssid}} = 1; # remember this save set } if ($config->VERBOSE() && scalar @sets) { print "Will recover save sets "; print $_->{line} . ' ' foreach @sets; print "\n"; printf("\nRange of dates: %s to %s\n\n", scalar localtime $sets[0]->{time}, scalar localtime $sets[-1]->{time}); } while (scalar @sets) { my @current = (); foreach (1..$config->SETS()) { my $set = shift @sets; push @current, $set if defined $set; } my $rr_command = "/usr/bin/nsr/recover -i $overwrite -s $server -d $where_to "; $rr_command .= sprintf("-S %s ", $_->{line}) foreach @current; if ($config->VERBOSE()) { printf("Save set %s of %s: now executing the recover command\n", $_->{line}, scalar(localtime($_->{time}))) foreach @current; } print "$rr_command\n"; if ($skip > 0) { print "(Skipped by your command)\n"; $skip--; next; } if ($n > 0) { system $rr_command; $n--; } else { my @current_print = map { $_->{line} } @current; print "Limit of sets to restore given by -n exceeded, skipping sets @current_print\n"; last; } } -- Note: To sign off this list, send a "signoff networker" command via email to listserv AT listmail.temple DOT edu or visit the list's Web site at http://listmail.temple.edu/archives/networker.html where you can also view and post messages to the list. =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=