1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-24 08:52:38 +02:00

Incorporate new test facility in pg_arman

This new facility has the advantage on not relying on static data when
generating the tests making the whole facility more robust. This is
basically taken from the upstream project pg_rman and adapted for the
sake of this pet project, so most of the credit go to Kyotaro Horiguchi
and Amit Langote regarding this facility. However I have adapted a bunch
of things and fixed a lot of redundancy and code duplication.
This commit is contained in:
Michael Paquier 2016-01-13 14:57:51 +09:00
parent 8559733103
commit 6de8b16403
42 changed files with 925 additions and 455 deletions

View File

@ -34,7 +34,7 @@ endif # ASCIIDOC
PG_CPPFLAGS = -I$(libpq_srcdir)
PG_LIBS = $(libpq_pgport)
REGRESS = option init show_validate backup_restore
REGRESS = init option show delete backup restore
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)

2
README
View File

@ -83,4 +83,4 @@ License
pg_arman can be distributed under the PostgreSQL license. See COPYRIGHT
file for more information. pg_arman is a fork of the existing project
pg_rman, initially created and maintained by NTT and Itagaki Takahiro.
pg_arman, initially created and maintained by NTT and Itagaki Takahiro.

View File

@ -1,13 +0,0 @@
# configuration
BACKUP_MODE=FULL
COMPRESS_DATA=NO
# result
TIMELINEID=1
START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-05-31 17:05:53'
END_TIME='2009-05-31 17:09:13'
DATA_BYTES=1242102558
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DONE

View File

@ -1 +0,0 @@
PG_VERSION f 4 4277607361 0600 2009-08-06 18:40:18

View File

@ -1,13 +0,0 @@
# configuration
BACKUP_MODE=PAGE
COMPRESS_DATA=NO
# result
TIMELINEID=1
START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-01 17:05:53'
END_TIME='2009-06-01 17:09:13'
DATA_BYTES=9223372036854775807
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DONE

View File

@ -1 +0,0 @@
PG_VERSION f 4 0 0600 2009-08-06 18:40:18

View File

@ -1,13 +0,0 @@
# configuration
BACKUP_MODE=FULL
COMPRESS_DATA=NO
# result
TIMELINEID=1
START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-02 17:05:03'
END_TIME='2009-06-02 17:05:03'
DATA_BYTES=-1
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=DELETED

View File

@ -1,13 +0,0 @@
# configuration
BACKUP_MODE=FULL
COMPRESS_DATA=NO
# result
TIMELINEID=1
START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-03 17:05:53'
END_TIME='2009-06-03 17:05:53'
DATA_BYTES=-1
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=RUNNING

View File

@ -389,7 +389,7 @@ pg_arman returns exit codes for each error status.
26 ERROR_PID_BROKEN postmaster.pid is broken
== AUTHOR ==
pg_arman is a fork of pg_rman that was originally written by NTT, now developed
pg_arman is a fork of pg_arman that was originally written by NTT, now developed
and maintained by Michael Paquier.
Please report bug reports at <https://github.com/michaelpq/pg_arman>.

50
expected/backup.out Normal file
View File

@ -0,0 +1,50 @@
\! bash sql/backup.sh
###### BACKUP COMMAND TEST-0001 ######
###### full backup mode ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
1
3
###### BACKUP COMMAND TEST-0002 ######
###### page-level backup mode ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
2
6
###### BACKUP COMMAND TEST-0003 ######
###### full backup with compression ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
1
0
3
###### BACKUP COMMAND TEST-0004 ######
###### full backup with smooth checkpoint ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
1
3
###### BACKUP COMMAND TEST-0005 ######
###### full backup with keep-data-generations and keep-data-days ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
The number of existing full backups validated is greater than 2.
OK. Let's try to test --keep-data-generations=1.
9
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
Number of remaining full backups validated: 2
Number of deleted backups : 2
6
###### BACKUP COMMAND TEST-0006 ######
###### switch backup mode from page to full ######
page-level backup without validated full backup
INFO: database backup start
ERROR: Valid full backup not found for differential backup. Either create a full backup or validate existing one.
10
0
0

View File

@ -1,26 +0,0 @@
\! sh sql/backup_restore.sh
CREATE TABLESPACE
CREATE DATABASE
# of deleted backups
0
full database backup
CHECKPOINT
differential database backup
CHECKPOINT
CHECKPOINT
stop DB during running pgbench
full database backup after recovery
CHECKPOINT
# of symbolic links in ARCLOG_PATH
0
# of recovery target option in recovery.conf
3
# of deleted backups (show all)
4
# of deleted backups
0
delete backup
# of deleted backups
4
# of deleted backups
8

20
expected/delete.out Normal file
View File

@ -0,0 +1,20 @@
\! bash sql/delete.sh
###### DELETE COMMAND TEST-0001 ######
###### delete full backups ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
try to delete the oldest backup
2
1
Number of deleted backups should be 1, is it so?: 1
###### DELETE COMMAND TEST-0002 ######
###### keep backups which are necessary for recovery ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
try to delete before third backup
3
1
Number of deleted backups should be 1, is it so?: 1

View File

@ -1,11 +1,33 @@
\! rm -rf results/init_test
\! pg_arman init -B ${PWD}/results/init_test --quiet;echo $?
\! bash sql/init.sh
###### INIT COMMAND TEST-0001 ######
###### success with archive_command ######
0
\! find results/init_test | xargs ls -Fd | sort
results/init_test/
results/init_test/backup/
results/init_test/backup/pg_xlog/
results/init_test/pg_arman.ini
\! pg_arman init -B ${PWD}/results/init_test --quiet;echo $?
results/init/backup/
results/init/backup/backup/
results/init/backup/backup/pg_xlog/
results/init/backup/pg_arman.ini
###### INIT COMMAND TEST-0002 ######
###### success with archive_command and log_directory ######
0
results/init/backup/
results/init/backup/backup/
results/init/backup/backup/pg_xlog/
results/init/backup/pg_arman.ini
###### 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
###### INIT COMMAND TEST-0004 ######
###### failure with backup catalog already existed ######
ERROR: backup catalog already exist. and it's not empty.
2
###### INIT COMMAND TEST-0005 ######
###### failure with backup catalog should be given as absolute path ######
ERROR: -B, --backup-path must be an absolute path
12

View File

@ -1,4 +1,6 @@
\! sh sql/option.sh
\! bash sql/option.sh
###### COMMAND OPTION TEST-0001 ######
###### help option ######
pg_arman manage backup/recovery of PostgreSQL database.
Usage:
@ -49,22 +51,66 @@ Generic options:
Read the website for details. <https://github.com/michaelpq/pg_arman>
Report bugs to <https://github.com/michaelpq/pg_arman/issues>.
1
###### COMMAND OPTION TEST-0002 ######
###### version option ######
pg_arman 0.1
1
###### COMMAND OPTION TEST-0003 ######
###### backup command failure without backup path option ######
ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)
ERROR: required parameter not specified: ARCLOG_PATH (-A, --arclog-path)
ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)
12
###### COMMAND OPTION TEST-0004 ######
###### backup command failure without backup mode option ######
ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode)
12
###### COMMAND OPTION TEST-0005 ######
###### backup command failure with invalid backup mode option ######
ERROR: invalid backup-mode "bad"
12
###### COMMAND OPTION TEST-0006 ######
###### delete failure without DATE ######
ERROR: required delete range option not specified: delete DATE
INFO: validate: 2009-05-31 17:05:53 backup and archive log files by CRC
INFO: validate: 2009-06-01 17:05:53 backup and archive log files by CRC
WARNING: CRC of backup file "PG_VERSION" must be 0 but FEF71BC1
WARNING: backup 2009-06-01 17:05:53 is corrupted
12
###### COMMAND OPTION TEST-0007 ######
###### syntax error in pg_arman.ini ######
WARNING: syntax error in " = INFINITE"
ERROR: Required parameter not specified: BACKUP_MODE (-b, --backup-mode)
12
###### COMMAND OPTION TEST-0008 ######
###### invalid value in pg_arman.ini ######
ERROR: invalid backup-mode ""
ERROR: invalid backup-mode "B"
12
###### COMMAND OPTION TEST-0009 ######
###### invalid value in pg_arman.ini ######
ERROR: option -Z, --compress-data should be a boolean: 'FOO'
12
###### COMMAND OPTION TEST-0010 ######
###### invalid value in pg_arman.ini ######
ERROR: option --keep-data-generations should be a 32bit signed integer: 'TRUE'
12
###### COMMAND OPTION TEST-0011 ######
###### invalid value in pg_arman.ini ######
ERROR: option -C, --smooth-checkpoint should be a boolean: 'FOO'
12
###### COMMAND OPTION TEST-0012 ######
###### invalid option in pg_arman.ini ######
ERROR: invalid option "TIMELINEID"
ERROR: invalid option "BACKUP_TARGETS"
12
###### COMMAND OPTION TEST-0013 ######
###### check priority of several pg_arman.ini files ######
ERROR: invalid backup-mode "ENV_PATH"
12

58
expected/restore.out Normal file
View File

@ -0,0 +1,58 @@
\! bash sql/restore.sh
###### RESTORE COMMAND TEST-0001 ######
###### recovery to latest from full backup ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
###### RESTORE COMMAND TEST-0002 ######
###### recovery to latest from full + page backups ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
###### RESTORE COMMAND TEST-0003 ######
###### recovery to latest from compressed full backup ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
###### RESTORE COMMAND TEST-0004 ######
###### recovery to target timeline ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
0
checking recovery.conf...
OK: recovery.conf has the given target timeline.
###### RESTORE COMMAND TEST-0005 ######
###### recovery to target time ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
###### RESTORE COMMAND TEST-0006 ######
###### recovery to target XID ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
OK: recovery-target-xid options works well.
###### RESTORE COMMAND TEST-0007 ######
###### recovery with target inclusive false ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
OK: recovery-target-inclusive=false works well.
###### RESTORE COMMAND TEST-0008 ######
###### recovery from page backup after database creation ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0

33
expected/show.out Normal file
View File

@ -0,0 +1,33 @@
\! bash sql/show.sh
###### SHOW COMMAND TEST-0001 ######
###### Status DONE and OK ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
OK: DONE status is shown properly.
0
OK: OK status is shown properly.
###### SHOW COMMAND TEST-0002 ######
###### Status RUNNING ######
OK: RUNNING status is shown properly.
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
###### SHOW COMMAND TEST-0003 ######
###### Status CORRUPT ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
remove a file from backup intentionally
0
OK: CORRUPT status is shown properly.
###### SHOW COMMAND TEST-0004 ######
###### Status DELETED ######
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
0
0
0
OK: DELETED status is shown properly.

View File

@ -1,44 +0,0 @@
-- test show command
\! rm -rf ${PWD}/results/sample_backup
\! cp -rp data/sample_backup ${PWD}/results/sample_backup
\! pg_arman show -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
==========================================================================
Start Mode Current TLI Parent TLI Time Data Status
==========================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- RUNNING
2009-06-01 17:05:53 PAGE 1 0 3m 9223PB DONE
2009-05-31 17:05:53 FULL 1 0 3m 1242MB DONE
\! pg_arman validate -B ${PWD}/results/sample_backup 2009-05-31 17:05:53 --debug
INFO: validate: 2009-05-31 17:05:53 backup and archive log files by CRC
LOG: database files...
LOG: (1/1) PG_VERSION
LOG: backup 2009-05-31 17:05:53 is valid
\! pg_arman validate -B ${PWD}/results/sample_backup 2009-06-01 17:05:53 --debug
INFO: validate: 2009-06-01 17:05:53 backup and archive log files by CRC
LOG: database files...
LOG: (1/1) PG_VERSION
WARNING: CRC of backup file "PG_VERSION" must be 0 but FEF71BC1
WARNING: backup 2009-06-01 17:05:53 is corrupted
\! pg_arman show -a -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
==========================================================================
Start Mode Current TLI Parent TLI Time Data Status
==========================================================================
2009-06-03 17:05:53 FULL 1 0 0m ---- RUNNING
2009-06-02 17:05:03 FULL 1 0 0m ---- DELETED
2009-06-01 17:05:53 PAGE 1 0 3m 9223PB CORRUPT
2009-05-31 17:05:53 FULL 1 0 3m 1242MB OK
\! pg_arman show 2009-06-01 17:05:53 -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
# configuration
BACKUP_MODE=PAGE
COMPRESS_DATA=false
# result
TIMELINEID=1
START_LSN=0/0b40c800
STOP_LSN=0/0b4c8020
START_TIME='2009-06-01 17:05:53'
END_TIME='2009-06-01 17:09:13'
RECOVERY_XID=0
DATA_BYTES=9223372036854775807
BLOCK_SIZE=8192
XLOG_BLOCK_SIZE=8192
STATUS=CORRUPT

View File

@ -21,7 +21,7 @@ const char *PROGRAM_EMAIL = "https://github.com/michaelpq/pg_arman/issues";
/* path configuration */
char *backup_path;
char *pgdata;
char *arclog_path;
char *arclog_path = NULL;
/* common configuration */
bool verbose = false;

91
sql/backup.sh Normal file
View File

@ -0,0 +1,91 @@
#!/bin/bash
#============================================================================
# This is a test script for backup command of pg_arman.
#============================================================================
# Load common rules
. sql/common.sh backup
init_backup
echo '###### BACKUP COMMAND TEST-0001 ######'
echo '###### full backup mode ######'
pg_arman backup -B ${BACKUP_PATH} -b full -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0001.log 2>&1
grep -c OK ${TEST_BASE}/TEST-0001.log
grep OK ${TEST_BASE}/TEST-0001.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
echo '###### BACKUP COMMAND TEST-0002 ######'
echo '###### page-level backup mode ######'
pg_arman backup -B ${BACKUP_PATH} -b page -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0002.log 2>&1
grep -c OK ${TEST_BASE}/TEST-0002.log
grep OK ${TEST_BASE}/TEST-0002.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
echo '###### BACKUP COMMAND TEST-0003 ######'
echo '###### full backup with compression ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0003.log 2>&1
grep -c OK ${TEST_BASE}/TEST-0003.log
grep OK ${TEST_BASE}/TEST-0003.log | grep -c true
grep OK ${TEST_BASE}/TEST-0003.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
echo '###### BACKUP COMMAND TEST-0004 ######'
echo '###### full backup with smooth checkpoint ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -C -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0004.log 2>&1
grep -c OK ${TEST_BASE}/TEST-0004.log
grep OK ${TEST_BASE}/TEST-0004.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
echo '###### BACKUP COMMAND TEST-0005 ######'
echo '###### full backup with keep-data-generations and keep-data-days ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0005-before.log 2>&1
NUM_OF_FULL_BACKUPS_BEFORE=`grep OK ${TEST_BASE}/TEST-0005-before.log | grep FULL | wc -l | sed 's/^ *//'`
if [ ${NUM_OF_FULL_BACKUPS_BEFORE} -gt 2 ] ; then
echo "The number of existing full backups validated is greater than 2."
echo "OK. Let's try to test --keep-data-generations=1."
else
echo "The number of existing full backups validated is not greater than 2."
echo "NG. There was something wrong in preparation of this test."
fi
# The actual value of NUM_OF_FULL_BACKUPS_BEFORE can vary on env, so commented out as default.
#echo "Number of existing full backups validated: ${NUM_OF_FULL_BACKUPS_BEFORE}"
grep OK ${TEST_BASE}/TEST-0005-before.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
pg_arman backup -B ${BACKUP_PATH} -b full --keep-data-days=-1 --keep-data-generations=1 -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show --show-all -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0005-after.log 2>&1
NUM_OF_FULL_BACKUPS_AFTER=`grep OK ${TEST_BASE}/TEST-0005-after.log | grep FULL | wc -l | sed 's/^ *//'`
echo "Number of remaining full backups validated: ${NUM_OF_FULL_BACKUPS_AFTER}"
NUM_OF_DELETED_BACKUPS=`grep DELETED ${TEST_BASE}/TEST-0005-after.log | wc -l | sed 's/^ *//'`
echo "Number of deleted backups : ${NUM_OF_DELETED_BACKUPS}"
grep OK ${TEST_BASE}/TEST-0005-after.log | sed -e 's@[^-]@@g' | wc -c | sed 's/^ *//'
echo '###### BACKUP COMMAND TEST-0006 ######'
echo '###### switch backup mode from page to full ######'
init_catalog
echo 'page-level backup without validated full backup'
pg_arman backup -B ${BACKUP_PATH} -b page -Z -p ${TEST_PGPORT} -d postgres;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0006.log 2>&1
grep OK ${TEST_BASE}/TEST-0006.log | grep FULL | wc -l | sed 's/^ *//'
grep ERROR ${TEST_BASE}/TEST-0006.log | grep INCR | wc -l | sed 's/^ *//'
# cleanup
## clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${TBLSPC_PATH}

2
sql/backup.sql Normal file
View File

@ -0,0 +1,2 @@
\! bash sql/backup.sh

View File

@ -1,238 +0,0 @@
#!/bin/sh
BASE_PATH=`pwd`
export PGDATA=$BASE_PATH/results/sample_database
export BACKUP_PATH=$BASE_PATH/results/sample_backup2
export ARCLOG_PATH=$BASE_PATH/results/arclog
export COMPRESS_DATA=YES
XLOG_PATH=$PGDATA/pg_xlog
TBLSPC_PATH=$BASE_PATH/results/tblspc
# Port used for test database cluster
TEST_PGPORT=54321
# configuration
SCALE=1
DURATION=10
ISOLATE_WAL=0
while [ $# -gt 0 ]; do
case $1 in
"-w")
ISOLATE_WAL=1
shift
;;
"-d")
DURATION=`expr $2 + 0`
if [ $? -ne 0 ]; then
echo "invalid duration"
exit 1
fi
shift 2
;;
"-s")
SCALE=`expr $2 + 0`
if [ $? -ne 0 ]; then
echo "invalid scale"
exit 1
fi
shift 2
;;
*)
shift
;;
esac
done
# delete old database cluster
pg_ctl stop -m immediate > /dev/null 2>&1
rm -rf $PGDATA
rm -rf $BASE_PATH/results/pg_xlog
rm -rf $ARCLOG_PATH
rm -rf $TBLSPC_PATH
# create new backup catalog
rm -rf $BACKUP_PATH
pg_arman init -B $BACKUP_PATH --quiet
# create default configuration file
cat << EOF > $BACKUP_PATH/pg_arman.ini
# comment
BACKUP_MODE = F # comment
EOF
# create new database cluster
initdb --no-locale > $BASE_PATH/results/initdb.log 2>&1
cat << EOF >> $PGDATA/postgresql.conf
port = $TEST_PGPORT
logging_collector = on
wal_level = archive
archive_mode = on
archive_command = 'cp "%p" "$ARCLOG_PATH/%f"'
log_filename = 'postgresql-%F_%H%M%S.log'
EOF
mkdir -p $ARCLOG_PATH
mkdir -p $TBLSPC_PATH
# isolate online WAL
if [ "$ISOLATE_WAL" -ne 0 ]; then
XLOG_PATH=$BASE_PATH/results/pg_xlog
mv $PGDATA/pg_xlog $XLOG_PATH
ln -s $XLOG_PATH $PGDATA/pg_xlog
fi
# start PostgreSQL
pg_ctl start -w -t 3600 > /dev/null 2>&1
# create tablespace and database for pgbench
mkdir -p $TBLSPC_PATH/pgbench
psql --no-psqlrc -p $TEST_PGPORT postgres <<EOF
CREATE TABLESPACE pgbench LOCATION '$TBLSPC_PATH/pgbench';
CREATE DATABASE pgbench TABLESPACE = pgbench;
EOF
# data_delete
export KEEP_DATA_GENERATIONS=2
export KEEP_DATA_DAYS=0
for i in `seq 1 5`; do
# pg_arman -p $TEST_PGPORT backup --verbose -d postgres > $BASE_PATH/results/log_full_0_$i 2>&1
pg_arman -w -p $TEST_PGPORT backup --verbose -d postgres > $BASE_PATH/results/log_full_0_$i 2>&1
done
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show_d_1 2>&1
echo "# of deleted backups"
grep -c DELETED $BASE_PATH/results/log_show_d_1
pgbench -p $TEST_PGPORT -i -s $SCALE pgbench > $BASE_PATH/results/pgbench.log 2>&1
echo "full database backup"
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
#pg_arman -p $TEST_PGPORT backup --verbose -d postgres > $BASE_PATH/results/log_full_1 2>&1
pg_arman -w -p $TEST_PGPORT backup --verbose -d postgres > $BASE_PATH/results/log_full_1 2>&1
pgbench -p $TEST_PGPORT -T $DURATION -c 10 pgbench >> $BASE_PATH/results/pgbench.log 2>&1
echo "differential database backup"
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
#pg_arman -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
pg_arman -w -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr1 2>&1
# validate all backup
pg_arman validate `date +%Y` --verbose > $BASE_PATH/results/log_validate1 2>&1
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show0 2>&1
pg_dumpall > $BASE_PATH/results/dump_before_rtx.sql
target_xid=`psql --no-psqlrc -p $TEST_PGPORT pgbench -tAq -c "INSERT INTO pgbench_history VALUES (1) RETURNING(xmin);"`
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
#pg_arman -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
pg_arman -w -p $TEST_PGPORT backup -b page --verbose -d postgres > $BASE_PATH/results/log_incr2 2>&1
pgbench -p $TEST_PGPORT -T $DURATION -c 10 pgbench >> $BASE_PATH/results/pgbench.log 2>&1
# stop PG during transaction and get commited info for verifing
echo "stop DB during running pgbench"
pgbench -p $TEST_PGPORT -T $DURATION -c 10 pgbench >> $BASE_PATH/results/pgbench.log 2>&1 &
sleep `expr $DURATION / 2`
pg_ctl stop -m immediate > /dev/null 2>&1
cp -rp $PGDATA $PGDATA.bak
pg_ctl start -w -t 3600 > /dev/null 2>&1
pg_dumpall > $BASE_PATH/results/dump_before.sql
# revert to crushed cluster
pg_ctl stop > /dev/null 2>&1
rm -rf $PGDATA
mv $PGDATA.bak $PGDATA
# validate all backup
pg_arman validate `date +%Y` --verbose > $BASE_PATH/results/log_validate2 2>&1
# restore check with pg_arman
pg_arman restore -! --verbose --check > $BASE_PATH/results/log_restore_check_1 2>&1
# restore with pg_arman
CUR_TLI=`pg_controldata | grep "Latest checkpoint's TimeLineID:" | awk '{print $4}'`
pg_arman restore -! --verbose > $BASE_PATH/results/log_restore1_1 2>&1
CUR_TLI_R=`grep "current timeline ID = " $BASE_PATH/results/log_restore1_1 | awk '{print $5}'`
TARGET_TLI=`grep "target timeline ID = " $BASE_PATH/results/log_restore1_1 | awk '{print $5}'`
if [ "$CUR_TLI" != "$CUR_TLI_R" ]; then
echo "failed: bad timeline ID" CUR_TLI=$CUR_TLI CUR_TLI_R=$CUR_TLI_R
fi
# recovery database
pg_ctl start -w -t 3600 > /dev/null 2>&1
# re-restore with pg_arman
pg_ctl stop -m immediate > /dev/null 2>&1
# restore check with pg_arman
pg_arman restore -! --verbose --check > $BASE_PATH/results/log_restore_check_2 2>&1
CUR_TLI=`pg_controldata | grep "Latest checkpoint's TimeLineID:" | awk '{print $4}'`
pg_arman restore -! --verbose > $BASE_PATH/results/log_restore1_2 2>&1
CUR_TLI_R=`grep "current timeline ID = " $BASE_PATH/results/log_restore1_2 | awk '{print $5}'`
TARGET_TLI=`grep "target timeline ID = " $BASE_PATH/results/log_restore1_2 | awk '{print $5}'`
if [ "$CUR_TLI" != "$CUR_TLI_R" ]; then
echo "failed: bad timeline ID" CUR_TLI=$CUR_TLI CUR_TLI_R=$CUR_TLI_R
fi
# re-recovery database
pg_ctl start -w -t 3600 > /dev/null 2>&1
# compare recovery results
pg_dumpall > $BASE_PATH/results/dump_after.sql
diff $BASE_PATH/results/dump_before.sql $BASE_PATH/results/dump_after.sql
# take a backup and delete backed up online files
# incrementa backup can't find last full backup because new timeline started.
echo "full database backup after recovery"
psql --no-psqlrc -p $TEST_PGPORT postgres -c "checkpoint"
#pg_arman -p $TEST_PGPORT backup -b full --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
pg_arman -w -p $TEST_PGPORT backup -b full --verbose -d postgres > $BASE_PATH/results/log_full2 2>&1
# Symbolic links in $ARCLOG_PATH should be deleted.
echo "# of symbolic links in ARCLOG_PATH"
find $ARCLOG_PATH -type l | wc -l | tr -d ' '
# restore with pg_arman
pg_ctl stop -m immediate > /dev/null 2>&1
# restore check with pg_arman
pg_arman restore -! --verbose --check > $BASE_PATH/results/log_restore_check_3 2>&1
CUR_TLI=`pg_controldata | grep "Latest checkpoint's TimeLineID:" | awk '{print $4}'`
pg_arman restore -! --recovery-target-xid $target_xid --recovery-target-inclusive false --verbose > $BASE_PATH/results/log_restore2 2>&1
CUR_TLI_R=`grep "current timeline ID = " $BASE_PATH/results/log_restore2 | awk '{print $5}'`
TARGET_TLI=`grep "target timeline ID = " $BASE_PATH/results/log_restore2 | awk '{print $5}'`
if [ "$CUR_TLI" != "$CUR_TLI_R" ]; then
echo "failed: bad timeline ID" CUR_TLI=$CUR_TLI CUR_TLI_R=$CUR_TLI_R
fi
echo "# of recovery target option in recovery.conf"
grep -c "recovery_target_" $PGDATA/recovery.conf
# recovery database
pg_ctl start -w -t 3600 > /dev/null 2>&1
pg_dumpall > $BASE_PATH/results/dump_after_rtx.sql
diff $BASE_PATH/results/dump_before_rtx.sql $BASE_PATH/results/dump_after_rtx.sql
# show
pg_arman -p $TEST_PGPORT show --verbose -a -d postgres > $BASE_PATH/results/log_show_timeline_1 2>&1
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show_timeline_2 2>&1
pg_arman -p $TEST_PGPORT show `date +%Y` --verbose -d postgres > $BASE_PATH/results/log_show_timeline_3 2>&1
echo "# of deleted backups (show all)"
grep -c DELETED $BASE_PATH/results/log_show_timeline_2
echo "# of deleted backups"
grep -c DELETED $BASE_PATH/results/log_show_timeline_3
echo "delete backup"
pg_arman -p $TEST_PGPORT delete --debug -d postgres > $BASE_PATH/results/log_delete1 2>&1
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show1 2>&1
echo "# of deleted backups"
grep -c DELETED $BASE_PATH/results/log_show1
pg_arman -p $TEST_PGPORT delete `date "+%Y-%m-%d %T"` --debug -d postgres > $BASE_PATH/results/log_delete2 2>&1
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show2 2>&1
echo "# of deleted backups"
grep -c DELETED $BASE_PATH/results/log_show2
pg_arman -p $TEST_PGPORT show `date +%Y` -a --verbose -d postgres > $BASE_PATH/results/log_show_timeline_4 2>&1
# cleanup
pg_ctl stop -m immediate > /dev/null 2>&1

View File

@ -1,2 +0,0 @@
\! sh sql/backup_restore.sh

84
sql/common.sh Normal file
View File

@ -0,0 +1,84 @@
#!/bin/bash
#============================================================================
# Common setup rules for all tests
#============================================================================
TEST_NAME=$1
# Unset environment variables usable by both Postgres and pg_arman
unset PGUSER
unset PGPORT
unset PGDATABASE
unset COMPRESS_DATA
unset BACKUP_MODE
unset ARCLOG_PATH
unset BACKUP_PATH
unset SMOOTH_CHECKPOINT
unset KEEP_DATA_GENERATIONS
unset KEEP_DATA_DAYS
unset RECOVERY_TARGET_TIME
unset RECOVERY_TARGET_XID
unset RECOVERY_TARGET_INCLUSIVE
unset RECOVERY_TARGET_TIMELINE
# Data locations
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
TBLSPC_PATH=${TEST_BASE}/tblspc
TEST_PGPORT=54321
export PGDATA=${PGDATA_PATH}
# Set of utility functions set across scripts to manage the tests
# Check presence of pgbench command and initialize environment
which pgbench > /dev/null 2>&1
ERR_NUM=$?
if [ $ERR_NUM != 0 ]
then
echo "pgbench is not installed in this environment."
echo "It is needed in PATH for those regression tests."
exit 1
fi
function cleanup()
{
# cleanup environment
pg_ctl stop -D ${PGDATA_PATH} -m immediate > /dev/null 2>&1
for folder in ${PGDATA_PATH} ${BACKUP_PATH} ${ARCLOG_PATH} ${TBLSPC_PATH}; do
rm -rf $folder
mkdir -p $folder
done
}
function init_catalog()
{
rm -fr ${BACKUP_PATH}
pg_arman init -B ${BACKUP_PATH} --quiet
}
function init_backup()
{
# cleanup environment
cleanup
# create new database cluster
initdb --no-locale -D ${PGDATA_PATH} > ${TEST_BASE}/initdb.log 2>&1
cp $PGDATA_PATH/postgresql.conf $PGDATA_PATH/postgresql.conf_org
cat << EOF >> $PGDATA_PATH/postgresql.conf
port = ${TEST_PGPORT}
logging_collector = on
wal_level = hot_standby
archive_mode = on
archive_command = 'cp %p ${ARCLOG_PATH}/%f'
EOF
# start PostgreSQL
pg_ctl start -D ${PGDATA_PATH} -w -t 300 > /dev/null 2>&1
pgbench -i -p ${TEST_PGPORT} -d postgres > ${TEST_BASE}/pgbench.log 2>&1
# init backup catalog
init_catalog
}

65
sql/delete.sh Normal file
View File

@ -0,0 +1,65 @@
#!/bin/bash
#============================================================================
# This is a test script for delete command of pg_arman.
#============================================================================
# Load common rules
. sql/common.sh delete
init_backup
echo '###### DELETE COMMAND TEST-0001 ######'
echo '###### delete full backups ######'
FIRST_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pgbench -p ${TEST_PGPORT} >> ${TEST_BASE}/pgbench.log 2>&1
SECOND_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pgbench -p ${TEST_PGPORT} >> ${TEST_BASE}/pgbench.log 2>&1
THIRD_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pg_arman validate -B ${BACKUP_PATH} --quiet
echo "try to delete the oldest backup"
pg_arman -B ${BACKUP_PATH} delete ${SECOND_BACKUP_DATE} > /dev/null 2>&1
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0001.out.1 2>&1
pg_arman show -a -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0001.out.2 2>&1
grep -c OK ${TEST_BASE}/TEST-0001.out.1
grep -c DELETED ${TEST_BASE}/TEST-0001.out.2
NUM_OF_DELETED_BACKUPS=`grep DELETED ${TEST_BASE}/TEST-0001.out.2 | wc -l | sed 's/^ *//'`
echo "Number of deleted backups should be 1, is it so?: ${NUM_OF_DELETED_BACKUPS}"
init_backup
echo '###### DELETE COMMAND TEST-0002 ######'
echo '###### keep backups which are necessary for recovery ######'
FIRST_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pgbench -p ${TEST_PGPORT} >> ${TEST_BASE}/pgbench.log 2>&1
SECOND_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pg_arman validate -B ${BACKUP_PATH} --quiet
pgbench -p ${TEST_PGPORT} >> ${TEST_BASE}/pgbench.log 2>&1
THIRD_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b page -Z -p ${TEST_PGPORT} -d postgres --quiet
pg_arman validate -B ${BACKUP_PATH} --quiet
FOURTH_BACKUP_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet
pg_arman validate -B ${BACKUP_PATH} --quiet
echo "try to delete before third backup"
pg_arman delete -B ${BACKUP_PATH} ${THIRD_BACKUP_DATE} > /dev/null 2>&1
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0002.out.1 2>&1
pg_arman show -a -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0002.out.2 2>&1
grep -c OK ${TEST_BASE}/TEST-0002.out.1
grep -c DELETED ${TEST_BASE}/TEST-0002.out.2
NUM_OF_DELETED_BACKUPS=`grep DELETED ${TEST_BASE}/TEST-0002.out.2 | wc -l | sed 's/^ *//'`
echo "Number of deleted backups should be 1, is it so?: ${NUM_OF_DELETED_BACKUPS}"
init_backup
# clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${SRVLOG_PATH}
rm -fr ${TBLSPC_PATH}

1
sql/delete.sql Normal file
View File

@ -0,0 +1 @@
\! bash sql/delete.sh

71
sql/init.sh Normal file
View File

@ -0,0 +1,71 @@
#!/bin/bash
#============================================================================
# This is a test script for init command of pg_arman.
#============================================================================
# Load common rules
. sql/common.sh init
# clean and create database cluster
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
cat << EOF >> ${PGDATA}/postgresql.conf
wal_level = hot_standby
archive_mode = on
archive_command = 'cp "%p" "${ARCLOG_PATH}/%f"'
EOF
echo '###### INIT COMMAND TEST-0001 ######'
echo '###### success with archive_command ######'
pg_arman -B ${BACKUP_PATH} init --quiet;echo $?
find results/init/backup | xargs ls -Fd | sort
echo '###### INIT COMMAND TEST-0002 ######'
echo '###### success with archive_command and log_directory ######'
rm -rf ${BACKUP_PATH}
cp ${PGDATA_PATH}/postgresql.conf_org ${PGDATA_PATH}/postgresql.conf
cat << EOF >> ${PGDATA}/postgresql.conf
wal_level = hot_standby
archive_mode = on
archive_command = 'cp "%p" "${ARCLOG_PATH}/%f"'
log_directory = '${SRVLOG_PATH}'
EOF
pg_arman -B ${BACKUP_PATH} init --quiet;echo $?
find results/init/backup | xargs ls -Fd | sort
echo '###### INIT COMMAND TEST-0003 ######'
echo '###### success without archive_command ######'
rm -rf ${BACKUP_PATH}
cp ${PGDATA_PATH}/postgresql.conf_org ${PGDATA_PATH}/postgresql.conf
cat << EOF >> ${PGDATA}/postgresql.conf
wal_level = hot_standby
archive_mode = on
log_directory = '${SRVLOG_PATH}'
EOF
pg_arman -B ${BACKUP_PATH} init --quiet;echo $?
find results/init/backup | xargs ls -Fd | sort
echo '###### INIT COMMAND TEST-0004 ######'
echo '###### failure with backup catalog already existed ######'
pg_arman -B ${BACKUP_PATH} init;echo $?
echo ''
echo '###### INIT COMMAND TEST-0005 ######'
echo '###### failure with backup catalog should be given as absolute path ######'
rm -rf ${BACKUP_PATH}
pg_arman --backup-path=resuts/init/backup init;echo $?
echo ''
# clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${SRVLOG_PATH}

View File

@ -1,4 +1 @@
\! rm -rf results/init_test
\! pg_arman init -B ${PWD}/results/init_test --quiet;echo $?
\! find results/init_test | xargs ls -Fd | sort
\! pg_arman init -B ${PWD}/results/init_test --quiet;echo $?
\! bash sql/init.sh

View File

@ -1,70 +1,99 @@
#!/bin/sh
#!/bin/bash
#============================================================================
# This is a test script for option test of pg_arman.
# This is a test script for options of pg_arman.
#============================================================================
BASE_PATH=`pwd`
# Load common rules
. sql/common.sh option
# Clear environment variables used by pg_arman except $PGDATA.
# List of environment variables is defined in catalog.c.
unset BACKUP_PATH
unset ARCLOG_PATH
unset BACKUP_MODE
unset COMPRESS_DATA
unset KEEP_DATA_GENERATIONS
unset KEEP_DATA_DAYS
cleanup
export PGDATA=$BASE_PATH/results/sample_database
echo '###### COMMAND OPTION TEST-0001 ######'
echo '###### help option ######'
pg_arman --help;echo $?
echo ''
# Note: not exported
BACKUP_PATH=$BASE_PATH/results/sample_backup2
echo '###### COMMAND OPTION TEST-0002 ######'
echo '###### version option ######'
pg_arman --version;echo $?
echo ''
# Setup backup catalog for backup test.
rm -rf $BACKUP_PATH
cp -rp data/sample_backup $BACKUP_PATH
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 $?
echo ''
# general option
pg_arman --help
pg_arman --version
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 $?
echo ''
# show option
# required argument check
pg_arman show
pg_arman show -B $BACKUP_PATH
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 ''
# backup option
# required arguments check
pg_arman backup --verbose
pg_arman backup --verbose -B $BACKUP_PATH
echo '###### COMMAND OPTION TEST-0006 ######'
echo '###### delete failure without DATE ######'
pg_arman delete -B ${BACKUP_PATH};echo $?
echo ''
# bad arguments check
pg_arman backup --verbose -B $BACKUP_PATH -b bad
init_backup
# delete or validate requires DATE
pg_arman delete -B $BACKUP_PATH
pg_arman validate -B $BACKUP_PATH
echo '###### COMMAND OPTION TEST-0007 ######'
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 $?
echo ''
# invalid configuration file check
echo " = INFINITE" > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo "BACKUP_MODE= " > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo "BACKUP_MODE=B" > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo "COMPRESS_DATA=FOO" > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo "TIMELINEID=-1" > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo "BACKUP_TARGETS=F" > $BACKUP_PATH/pg_arman.ini
pg_arman backup --verbose -B $BACKUP_PATH
echo '###### COMMAND OPTION TEST-0008 ######'
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 $?
echo ''
# configuration priorityfile check
echo "BACKUP_MODE=ENV_PATH" > $BACKUP_PATH/pg_arman.ini
mkdir $BACKUP_PATH/conf_path
echo "BACKUP_PATH=$BACKUP_PATH/conf_path" > $BACKUP_PATH/pg_arman.conf
echo "BACKUP_MODE=CONF_PATH" > $BACKUP_PATH/conf_path/pg_arman.ini
mkdir $BACKUP_PATH/comm_path
echo "BACKUP_MODE=COMM_PATH" > $BACKUP_PATH/comm_path/pg_arman.ini
export BACKUP_PATH=$BACKUP_PATH
pg_arman backup --verbose
echo '###### COMMAND OPTION TEST-0009 ######'
echo '###### invalid value in pg_arman.ini ######'
init_catalog
echo "COMPRESS_DATA=FOO" >> ${BACKUP_PATH}/pg_arman.ini
pg_arman backup -B ${BACKUP_PATH} -A ${ARCLOG_PATH} -b full -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 $?
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 $?
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 $?
echo ''
echo '###### COMMAND OPTION TEST-0013 ######'
echo '###### check priority of several pg_arman.ini files ######'
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 $?
echo ''
# clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${TBLSPC_PATH}

View File

@ -1 +1 @@
\! sh sql/option.sh
\! bash sql/option.sh

190
sql/restore.sh Normal file
View File

@ -0,0 +1,190 @@
#!/bin/bash
#============================================================================
# This is a test script for restore command of pg_arman.
#============================================================================
# Load common rules
. sql/common.sh restore
# Parameters exclusive to this test
SCALE=2
# Create some objects expected by pgbench
pgbench_objs()
{
NUM=$1
rm -rf ${TBLSPC_PATH}/pgbench
mkdir -p ${TBLSPC_PATH}/pgbench
psql --no-psqlrc -p ${TEST_PGPORT} -d postgres > /dev/null 2>&1 <<EOF
CREATE TABLESPACE pgbench LOCATION '${TBLSPC_PATH}/pgbench';
CREATE DATABASE pgbench TABLESPACE = pgbench;
EOF
pgbench -i -s ${SCALE} -p ${TEST_PGPORT} -d pgbench > ${TEST_BASE}/pgbench-${NUM}.log 2>&1
}
echo '###### RESTORE COMMAND TEST-0001 ######'
echo '###### recovery to latest from full backup ######'
init_backup
pgbench_objs 0001
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0001-before.out
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0001-after.out
diff ${TEST_BASE}/TEST-0001-before.out ${TEST_BASE}/TEST-0001-after.out
echo ''
echo '###### RESTORE COMMAND TEST-0002 ######'
echo '###### recovery to latest from full + page backups ######'
init_backup
pgbench_objs 0002
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
pg_arman backup -B ${BACKUP_PATH} -b page -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0002-before.out
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0002-after.out
diff ${TEST_BASE}/TEST-0002-before.out ${TEST_BASE}/TEST-0002-after.out
echo ''
echo '###### RESTORE COMMAND TEST-0003 ######'
echo '###### recovery to latest from compressed full backup ######'
init_backup
pgbench_objs 0003
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0003-before.out
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0003-after.out
diff ${TEST_BASE}/TEST-0003-before.out ${TEST_BASE}/TEST-0003-after.out
echo ''
echo '###### RESTORE COMMAND TEST-0004 ######'
echo '###### recovery to target timeline ######'
init_backup
pgbench_objs 0004
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0004-before.out
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
TARGET_TLI=`pg_controldata | grep " TimeLineID:" | awk '{print $4}'`
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --recovery-target-timeline=${TARGET_TLI} --quiet;echo $?
echo "checking recovery.conf..."
TARGET_TLI_IN_RECOVERY_CONF=`grep "recovery_target_timeline = " ${PGDATA_PATH}/recovery.conf | awk '{print $3}' | sed -e "s/'//g"`
if [ ${TARGET_TLI} = ${TARGET_TLI_IN_RECOVERY_CONF} ]; then
echo 'OK: recovery.conf has the given target timeline.'
else
echo 'NG: recovery.conf does not have the given target timeline.'
fi
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0004-after.out
diff ${TEST_BASE}/TEST-0004-before.out ${TEST_BASE}/TEST-0004-after.out
echo ''
echo '###### RESTORE COMMAND TEST-0005 ######'
echo '###### recovery to target time ######'
init_backup
pgbench_objs 0005
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0005-before.out
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
TARGET_TIME=`date +"%Y-%m-%d %H:%M:%S"`
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --recovery-target-time="${TARGET_TIME}" --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0005-after.out
diff ${TEST_BASE}/TEST-0005-before.out ${TEST_BASE}/TEST-0005-after.out
echo ''
echo '###### RESTORE COMMAND TEST-0006 ######'
echo '###### recovery to target XID ######'
init_backup
pgbench_objs 0006
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "CREATE TABLE tbl0006 (a text);" > /dev/null 2>&1
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pgbench -p ${TEST_PGPORT} pgbench > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0006-before.out
TARGET_XID=`psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -tAq -c "INSERT INTO tbl0006 VALUES ('inserted') RETURNING (xmin);"`
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --recovery-target-xid="${TARGET_XID}" --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0006-after.out
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM tbl0006;" > ${TEST_BASE}/TEST-0006-tbl.dump
diff ${TEST_BASE}/TEST-0006-before.out ${TEST_BASE}/TEST-0006-after.out
if grep "inserted" ${TEST_BASE}/TEST-0006-tbl.dump > /dev/null ; then
echo 'OK: recovery-target-xid options works well.'
else
echo 'NG: recovery-target-xid options does not work well.'
fi
echo ''
echo '###### RESTORE COMMAND TEST-0007 ######'
echo '###### recovery with target inclusive false ######'
init_backup
pgbench_objs 0007
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "CREATE TABLE tbl0007 (a text);" > /dev/null 2>&1
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pgbench -p ${TEST_PGPORT} pgbench > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0007-before.out
TARGET_XID=`psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -tAq -c "INSERT INTO tbl0007 VALUES ('inserted') RETURNING (xmin);"`
pgbench -p ${TEST_PGPORT} -d pgbench > /dev/null 2>&1
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --recovery-target-xid="${TARGET_XID}" --recovery-target-inclusive=false --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0007-after.out
psql --no-psqlrc -p ${TEST_PGPORT} -d pgbench -c "SELECT * FROM tbl0007;" > ${TEST_BASE}/TEST-0007-tbl.dump
diff ${TEST_BASE}/TEST-0007-before.out ${TEST_BASE}/TEST-0007-after.out
if grep "inserted" ${TEST_BASE}/TEST-0007-tbl.dump > /dev/null ; then
echo 'NG: recovery-target-inclusive=false does not work well.'
else
echo 'OK: recovery-target-inclusive=false works well.'
fi
echo ''
echo '###### RESTORE COMMAND TEST-0008 ######'
echo '###### recovery from page backup after database creation ######'
init_backup
pgbench_objs 0008
pg_ctl start -w -t 600 > /dev/null 2>&1
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
createdb db0008 -p ${TEST_PGPORT}
pgbench -i -s $SCALE -d db0008 -p ${TEST_PGPORT} > ${TEST_BASE}/TEST-0008-db0008-init.out 2>&1
pg_arman backup -B ${BACKUP_PATH} -b page -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet
pgbench -p ${TEST_PGPORT} -d db0008 >> ${TEST_BASE}/TEST-0008-db0008-init.out 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d db0008 -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0008-before.out
pg_ctl stop -m immediate > /dev/null 2>&1
pg_arman restore -B ${BACKUP_PATH} --quiet;echo $?
pg_ctl start -w -t 600 > /dev/null 2>&1
psql --no-psqlrc -p ${TEST_PGPORT} -d db0008 -c "SELECT * FROM pgbench_branches;" > ${TEST_BASE}/TEST-0008-after.out
diff ${TEST_BASE}/TEST-0008-before.out ${TEST_BASE}/TEST-0008-after.out
echo ''
# clean up the temporal test data
pg_ctl stop -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${TBLSPC_PATH}

2
sql/restore.sql Normal file
View File

@ -0,0 +1,2 @@
\! bash sql/restore.sh

82
sql/show.sh Normal file
View File

@ -0,0 +1,82 @@
#!/bin/bash
#============================================================================
# This is a test script for show command of pg_arman.
#============================================================================
# Load common rules
. sql/common.sh show
init_backup
echo '###### SHOW COMMAND TEST-0001 ######'
echo '###### Status DONE and OK ######'
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0001-show.out.1 2>&1
if grep "DONE" ${TEST_BASE}/TEST-0001-show.out.1 > /dev/null ; then
echo 'OK: DONE status is shown properly.'
else
echo 'NG: DONE status is not shown.'
fi
pg_arman validate -B ${BACKUP_PATH} --quiet;echo $?
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0001-show.out.2 2>&1
if grep "OK" ${TEST_BASE}/TEST-0001-show.out.2 > /dev/null ; then
echo 'OK: OK status is shown properly.'
else
echo 'NG: OK status is not shown.'
fi
echo ''
echo '###### SHOW COMMAND TEST-0002 ######'
echo '###### Status RUNNING ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet &
sleep 1
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0002-show.out 2>&1
if grep "RUNNING" ${TEST_BASE}/TEST-0002-show.out > /dev/null ; then
echo 'OK: RUNNING status is shown properly.'
else
echo 'NG: RUNNING status is not shown.'
fi
sleep 5
echo ''
echo '###### SHOW COMMAND TEST-0003 ######'
echo '###### Status CORRUPT ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
echo 'remove a file from backup intentionally'
rm -f `find ${BACKUP_PATH} -name postgresql.conf`
pg_arman validate -B ${BACKUP_PATH} --quiet > /dev/null 2>&1;echo $?
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0003-show.out 2>&1
if grep "CORRUPT" ${TEST_BASE}/TEST-0003-show.out > /dev/null ; then
echo 'OK: CORRUPT status is shown properly.'
else
echo 'NG: CORRUPT status is not shown.'
fi
echo ''
echo '###### SHOW COMMAND TEST-0004 ######'
echo '###### Status DELETED ######'
init_catalog
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet > /dev/null 2>&1;echo $?
DELETE_DATE=`date +"%Y-%m-%d %H:%M:%S"`
pg_arman backup -B ${BACKUP_PATH} -b full -Z -p ${TEST_PGPORT} -d postgres --quiet;echo $?
pg_arman validate -B ${BACKUP_PATH} --quiet > /dev/null 2>&1;echo $?
pg_arman delete ${DELETE_DATE} -B ${BACKUP_PATH} > /dev/null 2>&1;echo $?
pg_arman show -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0004-show.out 2>&1
pg_arman show -a -B ${BACKUP_PATH} > ${TEST_BASE}/TEST-0004-show-all.out 2>&1
if ! grep "DELETED" ${TEST_BASE}/TEST-0004-show.out > /dev/null && grep "DELETED" ${TEST_BASE}/TEST-0004-show-all.out > /dev/null ; then
echo 'OK: DELETED status is shown properly.'
else
echo 'NG: DELETED status is not shown.'
fi
echo ''
# clean up the temporal test data
pg_ctl stop -D ${PGDATA_PATH} -m immediate > /dev/null 2>&1
rm -fr ${PGDATA_PATH}
rm -fr ${BACKUP_PATH}
rm -fr ${ARCLOG_PATH}
rm -fr ${TBLSPC_PATH}

1
sql/show.sql Normal file
View File

@ -0,0 +1 @@
\! bash sql/show.sh

View File

@ -1,8 +0,0 @@
-- test show command
\! rm -rf ${PWD}/results/sample_backup
\! cp -rp data/sample_backup ${PWD}/results/sample_backup
\! pg_arman show -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
\! pg_arman validate -B ${PWD}/results/sample_backup 2009-05-31 17:05:53 --debug
\! pg_arman validate -B ${PWD}/results/sample_backup 2009-06-01 17:05:53 --debug
\! pg_arman show -a -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup
\! pg_arman show 2009-06-01 17:05:53 -A ${PWD}/results/arclog -B ${PWD}/results/sample_backup