From f0703e527c47e8c21b4167c3fe3326d0f493d481 Mon Sep 17 00:00:00 2001 From: stalkerg Date: Tue, 18 Oct 2016 20:22:53 +0300 Subject: [PATCH] Remove ARCLOG_PATH option. --- README.md | 6 ------ expected/init.out | 4 +++- expected/option.out | 6 ------ init.c | 48 +++------------------------------------------ pg_arman.c | 13 +++--------- pg_arman.h | 2 +- restore.c | 3 --- show.c | 4 ---- sql/common.sh | 2 +- sql/init.sh | 1 - sql/option.sh | 25 ++++++++++------------- 11 files changed, 21 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 96135b4b..50b16f0b 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,6 @@ Example backup (assuming PostgreSQL is running): ```bash # Init pg_aramn backup folder pg_arman init -B /home/postgres/backup/pgarman -cat << __EOF__ >> /home/postgres/backup/pgarman/pg_arman.ini -ARCLOG_PATH = '/home/postgres/backup/arman/wal' -__EOF__ # Make full backup with 2 thread and verbose mode. pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b full -v -j 2 # Validate backup @@ -142,9 +139,6 @@ Example backup (assuming PostgreSQL is running): ```bash # Init pg_aramn backup folder pg_arman init -B /home/postgres/backup/pgarman -cat << __EOF__ >> /home/postgres/backup/pgarman/pg_arman.ini -ARCLOG_PATH = '/home/postgres/backup/arman/wal' -__EOF__ # Make full backup with 2 thread and verbose mode. pg_arman backup -B /home/postgres/backup/pgarman -D /home/postgres/pgdata/arman -b full -v -j 2 --stream # Validate backup diff --git a/expected/init.out b/expected/init.out index 5bb09fd5..e52623a5 100644 --- a/expected/init.out +++ b/expected/init.out @@ -6,6 +6,7 @@ results/init/backup/ results/init/backup/backup/ results/init/backup/backup/pg_xlog/ results/init/backup/pg_arman.ini +results/init/backup/wal/ ###### INIT COMMAND TEST-0002 ###### ###### success with archive_command and log_directory ###### 0 @@ -13,14 +14,15 @@ results/init/backup/ results/init/backup/backup/ results/init/backup/backup/pg_xlog/ results/init/backup/pg_arman.ini +results/init/backup/wal/ ###### INIT COMMAND TEST-0003 ###### ###### success without archive_command ###### -WARNING: ARCLOG_PATH is not set because archive_command is empty.Please set ARCLOG_PATH in pg_arman.ini or environmental variable 0 results/init/backup/ results/init/backup/backup/ results/init/backup/backup/pg_xlog/ results/init/backup/pg_arman.ini +results/init/backup/wal/ ###### INIT COMMAND TEST-0004 ###### ###### failure with backup catalog already existed ###### ERROR: backup catalog already exist. and it's not empty diff --git a/expected/option.out b/expected/option.out index 45bda554..df838958 100644 --- a/expected/option.out +++ b/expected/option.out @@ -13,7 +13,6 @@ Usage: Common Options: -D, --pgdata=PATH location of the database storage area - -A, --arclog-path=PATH location of archive WAL storage area -B, --backup-path=PATH location of the backup storage area -c, --check show what would have been done -j, --threads=NUM num threads for backup and restore @@ -76,11 +75,6 @@ ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode) ERROR: invalid backup-mode "bad" 1 -###### COMMAND OPTION TEST-0006 ###### -###### delete failure without archive path ###### -ERROR: delete command needs ARCLOG_PATH (-A, --arclog-path) to be set -1 - ###### COMMAND OPTION TEST-0007 ###### ###### delete failure without DATE ###### ERROR: required delete range option not specified: delete DATE diff --git a/init.c b/init.c index cb3d8506..2c1e4291 100644 --- a/init.c +++ b/init.c @@ -30,6 +30,7 @@ int do_init(void) { char path[MAXPGPATH]; + char arclog_path_dir[MAXPGPATH]; char *log_directory = NULL; char *archive_command = NULL; FILE *fp; @@ -66,51 +67,8 @@ do_init(void) if (fp == NULL) elog(ERROR, "cannot create pg_arman.ini: %s", strerror(errno)); - /* set ARCLOG_PATH refered with log_directory */ - if (arclog_path == NULL && archive_command && archive_command[0]) - { - char *command = pgut_strdup(archive_command); - char *begin; - char *end; - char *fname; - - /* example: 'cp "%p" /path/to/arclog/"%f"' */ - for (begin = command; *begin;) - { - begin = begin + strspn(begin, " \n\r\t\v"); - end = begin + strcspn(begin, " \n\r\t\v"); - *end = '\0'; - - if ((fname = strstr(begin, "%f")) != NULL) - { - while (strchr(" \n\r\t\v\"'", *begin)) - begin++; - fname--; - while (fname > begin && strchr(" \n\r\t\v\"'/", fname[-1])) - fname--; - *fname = '\0'; - - if (is_absolute_path(begin)) - arclog_path = pgut_strdup(begin); - break; - } - - begin = end + 1; - } - - free(command); - } - if (arclog_path) - { - fprintf(fp, "ARCLOG_PATH='%s'\n", arclog_path); - elog(INFO, "ARCLOG_PATH is set to '%s'", arclog_path); - } - else if (archive_command && archive_command[0]) - elog(WARNING, "ARCLOG_PATH is not set because failed to parse archive_command '%s'." - "Please set ARCLOG_PATH in pg_arman.ini or environmental variable", archive_command); - else - elog(WARNING, "ARCLOG_PATH is not set because archive_command is empty." - "Please set ARCLOG_PATH in pg_arman.ini or environmental variable"); + join_path_components(arclog_path_dir, backup_path, "wal"); + dir_create_dir(arclog_path_dir, DIR_PERMISSION); fprintf(fp, "\n"); fclose(fp); diff --git a/pg_arman.c b/pg_arman.c index 4b2e0e05..3da6c098 100644 --- a/pg_arman.c +++ b/pg_arman.c @@ -22,7 +22,7 @@ const char *PROGRAM_EMAIL = "https://github.com/stalkerg/pg_arman/issues"; /* path configuration */ char *backup_path; char *pgdata; -char *arclog_path = NULL; +char arclog_path[MAXPGPATH]; /* common configuration */ bool check = false; @@ -57,7 +57,6 @@ static pgut_option options[] = { /* directory options */ { 's', 'D', "pgdata", &pgdata, SOURCE_ENV }, - { 's', 'A', "arclog-path", &arclog_path, SOURCE_ENV }, { 's', 'B', "backup-path", &backup_path, SOURCE_ENV }, /* common options */ { 'b', 'c', "check", &check }, @@ -171,18 +170,13 @@ main(int argc, char *argv[]) elog(ERROR, "-B, --backup-path must be an absolute path"); if (pgdata != NULL && !is_absolute_path(pgdata)) elog(ERROR, "-D, --pgdata must be an absolute path"); - if (arclog_path != NULL && !is_absolute_path(arclog_path)) - elog(ERROR, "-A, --arclog-path must be an absolute path"); - /* Sanity checks with commands */ - if (pg_strcasecmp(cmd, "delete") == 0 && arclog_path == NULL) - elog(ERROR, "delete command needs ARCLOG_PATH (-A, --arclog-path) to be set"); + join_path_components(arclog_path, backup_path, "wal"); /* setup exclusion list for file search */ for (i = 0; pgdata_exclude[i]; i++); /* find first empty slot */ - if (arclog_path) - pgdata_exclude[i++] = arclog_path; + pgdata_exclude[i++] = arclog_path; if(!backup_logs) pgdata_exclude[i++] = "pg_log"; @@ -241,7 +235,6 @@ pgut_help(bool details) printf(_("\nCommon Options:\n")); printf(_(" -D, --pgdata=PATH location of the database storage area\n")); - printf(_(" -A, --arclog-path=PATH location of archive WAL storage area\n")); printf(_(" -B, --backup-path=PATH location of the backup storage area\n")); printf(_(" -c, --check show what would have been done\n")); printf(_(" -j, --threads=NUM num threads for backup and restore\n")); diff --git a/pg_arman.h b/pg_arman.h index f6ccd9e0..d6300a73 100644 --- a/pg_arman.h +++ b/pg_arman.h @@ -196,7 +196,7 @@ typedef union DataPage /* path configuration */ extern char *backup_path; extern char *pgdata; -extern char *arclog_path; +extern char arclog_path[MAXPGPATH]; /* common configuration */ extern bool check; diff --git a/restore.c b/restore.c index 89022a70..5936a925 100644 --- a/restore.c +++ b/restore.c @@ -68,9 +68,6 @@ do_restore(const char *target_time, if (pgdata == NULL) elog(ERROR, "required parameter not specified: PGDATA (-D, --pgdata)"); - if (arclog_path == NULL) - elog(ERROR, - "required parameter not specified: ARCLOG_PATH (-A, --arclog-path)"); elog(LOG, "========================================"); elog(LOG, "restore start"); diff --git a/show.c b/show.c index f5c247db..94640484 100644 --- a/show.c +++ b/show.c @@ -25,10 +25,6 @@ do_show(pgBackupRange *range, bool show_all) * the parent TLI from history field generated by server after * child timeline is chosen. */ - if (arclog_path == NULL) - elog(ERROR, - "required parameter not specified: ARCLOG_PATH (-A, --arclog-path)"); - if (pgBackupRangeIsSingle(range)) { pgBackup *backup; diff --git a/sql/common.sh b/sql/common.sh index d5fb149c..5e69d20e 100644 --- a/sql/common.sh +++ b/sql/common.sh @@ -26,7 +26,7 @@ BASE_PATH=`pwd` TEST_BASE=${BASE_PATH}/results/${TEST_NAME} PGDATA_PATH=${TEST_BASE}/data BACKUP_PATH=${TEST_BASE}/backup -ARCLOG_PATH=${TEST_BASE}/arclog +ARCLOG_PATH=${BACKUP_PATH}/wal TBLSPC_PATH=${TEST_BASE}/tblspc TEST_PGPORT=54321 export PGDATA=${PGDATA_PATH} diff --git a/sql/init.sh b/sql/init.sh index 467ff189..085253d1 100644 --- a/sql/init.sh +++ b/sql/init.sh @@ -11,7 +11,6 @@ pg_ctl stop -m immediate > /dev/null 2>&1 rm -fr ${PGDATA} rm -fr ${BACKUP_PATH} -rm -fr ${ARCLOG_PATH} && mkdir -p ${ARCLOG_PATH} initdb --no-locale > /dev/null 2>&1 cp ${PGDATA}/postgresql.conf ${PGDATA}/postgresql.conf_org diff --git a/sql/option.sh b/sql/option.sh index d3a35c1b..502d741c 100644 --- a/sql/option.sh +++ b/sql/option.sh @@ -21,27 +21,22 @@ echo '' echo '###### COMMAND OPTION TEST-0003 ######' echo '###### backup command failure without backup path option ######' -pg_arman backup -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $? +pg_arman backup -b full -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0004 ######' echo '###### backup command failure without backup mode option ######' -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0005 ######' echo '###### backup command failure with invalid backup mode option ######' -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b bad -p ${TEST_PGPORT};echo $? -echo '' - -echo '###### COMMAND OPTION TEST-0006 ######' -echo '###### delete failure without archive path ######' -pg_arman delete -B ${BACKUP_PATH};echo $? +pg_arman backup -B ${BACKUP_PATH} -b bad -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0007 ######' echo '###### delete failure without DATE ######' -pg_arman delete -B ${BACKUP_PATH} -A ${ARCLOG_PATH};echo $? +pg_arman delete -B ${BACKUP_PATH};echo $? echo '' init_backup @@ -49,35 +44,35 @@ init_backup echo '###### COMMAND OPTION TEST-0008 ######' echo '###### syntax error in pg_arman.ini ######' echo " = INFINITE" >> ${BACKUP_PATH}/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0009 ######' echo '###### invalid value in pg_arman.ini ######' init_catalog echo "BACKUP_MODE=" >> ${BACKUP_PATH}/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0010 ######' echo '###### invalid value in pg_arman.ini ######' init_catalog echo "KEEP_DATA_GENERATIONS=TRUE" >> ${BACKUP_PATH}/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -b full -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0011 ######' echo '###### invalid value in pg_arman.ini ######' init_catalog echo "SMOOTH_CHECKPOINT=FOO" >> ${BACKUP_PATH}/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -b full -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0012 ######' echo '###### invalid option in pg_arman.ini ######' init_catalog echo "TIMELINEID=1" >> ${BACKUP_PATH}/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -b full -p ${TEST_PGPORT};echo $? echo '' echo '###### COMMAND OPTION TEST-0013 ######' @@ -86,7 +81,7 @@ init_catalog mkdir -p ${BACKUP_PATH}/conf_path_a echo "BACKUP_MODE=ENV_PATH" > ${BACKUP_PATH}/pg_arman.ini echo "BACKUP_MODE=ENV_PATH_A" > ${BACKUP_PATH}/conf_path_a/pg_arman.ini -pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -p ${TEST_PGPORT};echo $? +pg_arman backup -B ${BACKUP_PATH} -p ${TEST_PGPORT};echo $? echo '' # clean up the temporal test data