diff --git a/bin/recovery-till-timestamp-update.sh b/bin/recovery-till-timestamp-update.sh new file mode 100755 index 0000000..dfa6d03 --- /dev/null +++ b/bin/recovery-till-timestamp-update.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +#The script will update recovery-till-timestamp value in the config file used by omnipitr-restore. +#It accepts two arguments +#$1 = Absolute Path of the config file +#$2 = The New Timetsamp (Format : 2013-03-12 22:00:00 ) +#Example : ./recovery-till-timestamp-update.sh /data_dir/omniti-restore-config.cfg "$(date +'%Y-%m-%d 22:00:00')" + +die () { + echo >&2 "$@" + exit 1 +} + +[ "$#" -eq 2 ] || die "2 argument required,conf file and timestamp , $# provided" +CONFIG_FILE="$1" +NEW_TIMESTAMP="$2" + + +if [ -f $CONFIG_FILE ] ; then + sed -i "s/.*--recovery-till-timestamp[ |\=].*/--recovery-till-timestamp = $NEW_TIMESTAMP /g" $CONFIG_FILE +else + echo "Config File $CONFIG_FILE does not exist" +fi + diff --git a/lib/OmniPITR/Program.pm b/lib/OmniPITR/Program.pm index e692aa1..a290d73 100644 --- a/lib/OmniPITR/Program.pm +++ b/lib/OmniPITR/Program.pm @@ -534,7 +534,12 @@ sub _load_config_file { elsif ( /\A\s*(-[^\s=]*)\s*[\s=]\s*(.*)\z/ ) { # -x=123 or -x 123 +<<<<<<< HEAD + push @new_args, $1; + push @new_args, $2; +======= push @new_args, $1, $2; +>>>>>>> 2bd3568e1eaaceb874c2a08d72631b88b8363bc7 } else { croak( "Cannot parse line: $_\n" ); diff --git a/lib/OmniPITR/Program/Restore.pm b/lib/OmniPITR/Program/Restore.pm index b6172a6..6d9b928 100644 --- a/lib/OmniPITR/Program/Restore.pm +++ b/lib/OmniPITR/Program/Restore.pm @@ -15,6 +15,9 @@ use Storable; use Data::Dumper; use Getopt::Long qw( :config no_ignore_case ); use Cwd; +use Date::Parse; +#use OmniPITR::Program; + =head1 run() @@ -47,6 +50,20 @@ sub run { next if $self->{ 'finish' }; sleep 1; $self->do_some_removal(); + #Do Check for Config file reload + my @file_info = stat( $OmniPITR::Program::config_file_name ); + my $file_mtime = $file_info[ 9 ]; + my $ok_since = time() - $file_mtime; + if ( $ok_since <= 60 ) { + if ( ( $self->verbose ) + && ( !$self->{ 'logged_delay' } ) ) + { + $self->log->log( 'Exiting as conf file %s got modified (conf file mtime = %u, thrashhold for refresh %u)', $OmniPITR::Program::config_file_name,$file_mtime, $ok_since ); + $self->{ 'logged_delay' } = 1; + } + exit (0); + } + } } @@ -281,6 +298,7 @@ method. =cut sub try_to_restore_and_exit { + my $self = shift; if ( $self->{ 'finish' } eq 'immediate' ) { @@ -304,6 +322,29 @@ sub try_to_restore_and_exit { return; } +#Adding module for restoring till a particular time stamp + + if ( ( $self->{ 'recovery-till-timestamp' } ) + && ( !$self->{ 'finish' } ) ) + { + my @file_info = stat( $wanted_file ); + my $file_mtime = $file_info[ 9 ]; + my $last_xlog_time = str2time($self->{'recovery-till-timestamp'}); + my $ok_since = $last_xlog_time ; + if ( $ok_since <= $file_mtime ) { + if ( ( $self->verbose ) + && ( !$self->{ 'logged_delay' } ) ) + { + $self->log->log( 'Segment %s found, but it is newer than timestamp %s (mtime = %u, accepted since %u)', $self->{ 'segment' }, $self->{'recovery-till-timestamp'},$file_mtime, $ok_since ); + $self->{ 'logged_delay' } = 1; + } + return; + } + } + +#----------- + + if ( ( $self->{ 'recovery-delay' } ) && ( !$self->{ 'finish' } ) ) { @@ -415,6 +456,7 @@ sub read_args_specification { 'pid-file' => { 'type' => 's', }, 'pre-removal-processing' => { 'type' => 's', 'aliases' => [ 'h' ], }, 'recovery-delay' => { 'type' => 'i', 'aliases' => [ 'w' ], }, + 'recovery-till-timestamp'=> { 'type' => 's', 'aliases' => [ 'rtt' ],}, 'removal-pause-trigger' => { 'type' => 's', 'aliases' => [ 'p' ], }, 'remove-at-a-time' => { 'type' => 'i', 'aliases' => [ 'rt' ], 'default' => '3', }, 'remove-before' => { 'aliases' => [ 'rb' ], },