Skip to content
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

fix the range of keep data generation #218

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 23 additions & 8 deletions expected/option.out
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Report bugs to <http://github.com/ossc-db/pg_rman/issues>.

###### COMMAND OPTION TEST-0002 ######
###### version option ######
pg_rman 1.3.13
pg_rman 1.3.14
1

###### COMMAND OPTION TEST-0003 ######
Expand Down Expand Up @@ -136,40 +136,55 @@ ERROR: option --keep-arclog-days should be a 32bit signed integer: 'TRUE'

###### COMMAND OPTION TEST-0014 ######
###### invalid value in pg_rman.ini ######
ERROR: option --keep-srvlog-files should be a 32bit signed integer: 'TRUE'
ERROR: option --keep-srvlog-files should be between 1 and 2147483647: 'TRUE'
12

###### COMMAND OPTION TEST-0015 ######
###### invalid value in pg_rman.ini ######
ERROR: option --keep-srvlog-days should be a 32bit signed integer: 'TRUE'
ERROR: option --keep-srvlog-days should be between 1 and 2147483647: 'TRUE'
12

###### COMMAND OPTION TEST-0016 ######
###### invalid value in pg_rman.ini ######
ERROR: option --keep-data-generations should be a 32bit signed integer: 'TRUE'
ERROR: option --keep-data-generations should be between 1 and 2147483647: 'TRUE'
12

###### COMMAND OPTION TEST-0017 ######
###### invalid value in pg_rman.ini ######
ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO'
ERROR: option --keep-data-generations should be between 1 and 2147483647: '0'
12

###### COMMAND OPTION TEST-0018 ######
###### invalid value in pg_rman.ini ######
ERROR: option -s, --with-serverlog should be a boolean: 'FOO'
ERROR: option --keep-srvlog-files should be between 1 and 2147483647: '0'
12

###### COMMAND OPTION TEST-0019 ######
###### invalid value in pg_rman.ini ######
ERROR: option --hard-copy should be a boolean: 'FOO'
ERROR: option --keep-srvlog-days should be between 1 and 2147483647: '0'
12

###### COMMAND OPTION TEST-0020 ######
###### invalid value in pg_rman.ini ######
ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO'
12

###### COMMAND OPTION TEST-0021 ######
###### invalid value in pg_rman.ini ######
ERROR: option -s, --with-serverlog should be a boolean: 'FOO'
12

###### COMMAND OPTION TEST-0022 ######
###### invalid value in pg_rman.ini ######
ERROR: option --hard-copy should be a boolean: 'FOO'
12

###### COMMAND OPTION TEST-0023 ######
###### invalid option in pg_rman.ini ######
ERROR: invalid option "TIMELINEID"
12

###### COMMAND OPTION TEST-0021 ######
###### COMMAND OPTION TEST-0024 ######
###### check priority of several pg_rman.ini files ######
ERROR: invalid backup-mode "ENV_PATH"
12
Expand Down
8 changes: 4 additions & 4 deletions pg_rman.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <time.h>
#include <sys/stat.h>

const char *PROGRAM_VERSION = "1.3.13";
const char *PROGRAM_VERSION = "1.3.14";
const char *PROGRAM_URL = "http://github.com/ossc-db/pg_rman";
const char *PROGRAM_ISSUES = "http://github.com/ossc-db/pg_rman/issues";

Expand Down Expand Up @@ -82,12 +82,12 @@ static pgut_option options[] =
/* delete options */
{ 'b', 'f', "force" , &force , SOURCE_ENV },
/* options with only long name (keep-xxx) */
{ 'i', 1, "keep-data-generations" , &keep_data_generations, SOURCE_ENV },
{ 'n', 1, "keep-data-generations" , &keep_data_generations, SOURCE_ENV },
{ 'i', 2, "keep-data-days" , &keep_data_days , SOURCE_ENV },
{ 'i', 3, "keep-arclog-files" , &keep_arclog_files , SOURCE_ENV },
{ 'i', 4, "keep-arclog-days" , &keep_arclog_days , SOURCE_ENV },
{ 'i', 5, "keep-srvlog-files" , &keep_srvlog_files , SOURCE_ENV },
{ 'i', 6, "keep-srvlog-days" , &keep_srvlog_days , SOURCE_ENV },
{ 'n', 5, "keep-srvlog-files" , &keep_srvlog_files , SOURCE_ENV },
{ 'n', 6, "keep-srvlog-days" , &keep_srvlog_days , SOURCE_ENV },
/* restore options */
{ 's', 7, "recovery-target-time" , &target_time , SOURCE_ENV },
{ 's', 8, "recovery-target-xid" , &target_xid , SOURCE_ENV },
Expand Down
39 changes: 39 additions & 0 deletions pgut/pgut.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ assign_option(pgut_option *opt, const char *optarg, pgut_optsrc src)
return;
message = "a 32bit signed integer";
break;
case 'n':
if (parse_posi(optarg, opt->var))
return;
message = "between 1 and 2147483647";
break;
case 'u':
if (parse_uint32(optarg, opt->var))
return;
Expand Down Expand Up @@ -386,6 +391,40 @@ parse_int32(const char *value, int32 *result)
return true;
}


/*
* Parse string as positive number.
* valid range: 1 ~ 2147483647
*/

bool
parse_posi(const char *value, int32 *result)
{
int64 val;
char *endptr;

if (strcmp(value, INFINITE_STR) == 0)
{
*result = INT_MAX;
return true;
}

errno = 0;
val = strtol(value, &endptr, 0);
if (endptr == value || *endptr)
return false;

if (errno == ERANGE || val != (int64) ((int32) val))
return false;

if (val < 0 || val == 0)
return false;

*result = val;

return true;
}

/*
* Parse string as 32bit unsigned int.
* valid range: 0 ~ 4294967295 (2^32-1)
Expand Down
1 change: 1 addition & 0 deletions pgut/pgut.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ extern bool parse_int64(const char *value, int64 *result);
extern bool parse_uint64(const char *value, uint64 *result);
extern bool parse_time(const char *value, time_t *time);
extern bool parse_pair(const char buffer[], char key[], char value[]);
extern bool parse_posi(const char *value, int32 *result);

#define IsSpace(c) (isspace((unsigned char)(c)))
#define IsAlpha(c) (isalpha((unsigned char)(c)))
Expand Down
30 changes: 26 additions & 4 deletions sql/option.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,54 @@ echo ''
echo '###### COMMAND OPTION TEST-0017 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "SMOOTH_CHECKPOINT=FOO" >> ${BACKUP_PATH}/pg_rman.ini
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better not to change this line and change line 190 because the number of diff became minimum.

echo "KEEP_DATA_GENERATIONS=0" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0018 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "WITH_SERVERLOG=FOO" >> ${BACKUP_PATH}/pg_rman.ini
echo "KEEP_SRVLOG_FILES=0" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0019 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "HARD_COPY=FOO" >> ${BACKUP_PATH}/pg_rman.ini
echo "KEEP_SRVLOG_DAYS=0" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''


echo '###### COMMAND OPTION TEST-0020 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "SMOOTH_CHECKPOINT=FOO" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0021 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "WITH_SERVERLOG=FOO" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0022 ######'
echo '###### invalid value in pg_rman.ini ######'
init_catalog
echo "HARD_COPY=FOO" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0023 ######'
echo '###### invalid option in pg_rman.ini ######'
init_catalog
echo "TIMELINEID=1" >> ${BACKUP_PATH}/pg_rman.ini
pg_rman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $?
echo ''

echo '###### COMMAND OPTION TEST-0021 ######'
echo '###### COMMAND OPTION TEST-0024 ######'
echo '###### check priority of several pg_rman.ini files ######'
init_catalog
mkdir -p ${BACKUP_PATH}/conf_path_a
Expand Down