Skip to content

Bug Fix for reading the options from conf file and addition of one option recovery-till-timestamp #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bin/recovery-till-timestamp-update.sh
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions lib/OmniPITR/Program.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
42 changes: 42 additions & 0 deletions lib/OmniPITR/Program/Restore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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);
}

}
}

Expand Down Expand Up @@ -281,6 +298,7 @@ method.
=cut

sub try_to_restore_and_exit {

my $self = shift;

if ( $self->{ 'finish' } eq 'immediate' ) {
Expand All @@ -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' } ) )
{
Expand Down Expand Up @@ -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' ], },
Expand Down