-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement database composer and partial fetch for Postgres (#1434)
* Add Database Composer * Add skipDirectory option * Add only databases option * Style fix * Update flags * Update flags * Files filtering to new ExtractProvider * Full database composer docker test * Style issues * Add partial backup docker test * Add Docker test to CI & Update config.go * Add tests to CI * Docker test: Add check for skipped database * Add documentation
- Loading branch information
1 parent
0b5f127
commit dfb04c8
Showing
18 changed files
with
417 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
docker/pg_tests/Dockerfile_full_backup_database_composer_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM wal-g/docker_prefix:latest | ||
|
||
CMD su postgres -c "/tmp/tests/full_backup_database_composer_test.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM wal-g/docker_prefix:latest | ||
|
||
CMD su postgres -c "/tmp/tests/partial_backup_test.sh" |
4 changes: 4 additions & 0 deletions
4
docker/pg_tests/scripts/configs/full_backup_database_composer_test_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"WALE_S3_PREFIX": "s3://fulldatabasecomposerbucket", | ||
"WALG_DELTA_MAX_STEPS": "6", | ||
"WALG_PGP_KEY_PATH": "/tmp/PGP_KEY", | ||
"WALG_USE_DATABASE_COMPOSER": "true" |
3 changes: 3 additions & 0 deletions
3
docker/pg_tests/scripts/configs/partial_backup_test_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"WALE_S3_PREFIX": "s3://partialbucket", | ||
"WALG_DELTA_MAX_STEPS": "6", | ||
"WALG_PGP_KEY_PATH": "/tmp/PGP_KEY" |
12 changes: 12 additions & 0 deletions
12
docker/pg_tests/scripts/tests/full_backup_database_composer_test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
set -e -x | ||
CONFIG_FILE="/tmp/configs/full_backup_database_composer_test_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cat ${CONFIG_FILE} > ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
|
||
. /tmp/tests/test_functions/test_full_backup.sh | ||
test_full_backup ${TMP_CONFIG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh | ||
set -e -x | ||
CONFIG_FILE="/tmp/configs/partial_backup_test_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cat ${CONFIG_FILE} > ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
|
||
wal-g --config=${TMP_CONFIG} delete everything FORCE --confirm | ||
|
||
/usr/lib/postgresql/10/bin/initdb ${PGDATA} | ||
|
||
echo "archive_mode = on" >> ${PGDATA}/postgresql.conf | ||
echo "archive_command = 'wal-g --config=${TMP_CONFIG} wal-push %p && echo \"WAL pushing: %p\"'" >> ${PGDATA}/postgresql.conf | ||
|
||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA} -w start | ||
/tmp/scripts/wait_while_pg_not_ready.sh | ||
|
||
psql -c "CREATE DATABASE first" postgres | ||
psql -c "CREATE DATABASE second" postgres | ||
psql -c "CREATE TABLE tbl1 (data integer); INSERT INTO tbl1 VALUES (1), (2);" first | ||
psql -c "CREATE TABLE tbl2 (data integer); INSERT INTO tbl2 VALUES (3), (4);" second | ||
sleep 1 | ||
|
||
wal-g --config=${TMP_CONFIG} backup-push ${PGDATA} | ||
|
||
psql -c "INSERT INTO tbl1 VALUES (5), (6);" first | ||
psql -c "INSERT INTO tbl2 VALUES (7), (8);" second | ||
FIRST_OID=$(psql -t -c "SELECT oid FROM pg_database WHERE datname = 'first';" -d postgres -A;) | ||
T0_OID=$(psql -t -c "SELECT oid FROM pg_database WHERE datname = 'template0';" -d postgres -A;) | ||
T1_OID=$(psql -t -c "SELECT oid FROM pg_database WHERE datname = 'template1';" -d postgres -A;) | ||
PG_OID=$(psql -t -c "SELECT oid FROM pg_database WHERE datname = 'postgres';" -d postgres -A;) | ||
psql -c "SELECT pg_switch_wal();" postgres | ||
sleep 10 | ||
|
||
/tmp/scripts/drop_pg.sh | ||
wal-g --config=${TMP_CONFIG} backup-fetch ${PGDATA} LATEST --restore-only=${T1_OID},${T0_OID},${PG_OID},${FIRST_OID} | ||
echo "restore_command = 'echo \"WAL file restoration: %f, %p\"&& wal-g --config=${TMP_CONFIG} wal-fetch \"%f\" \"%p\"'" > ${PGDATA}/recovery.conf | ||
|
||
/usr/lib/postgresql/10/bin/pg_ctl -D ${PGDATA} -w start | ||
/tmp/scripts/wait_while_pg_not_ready.sh | ||
|
||
if [ "$(psql -t -c "select data from tbl1;" -d first -A)" = "$(printf '1\n2\n5\n6')" ]; then | ||
echo "Partial backup success!!!!!!" | ||
else | ||
echo "Partial backup doesn't work :(" | ||
exit 1 | ||
fi | ||
|
||
if psql -t -c "select data from tbl2;" -d second -A 2>&1 | grep -q "is not a valid data directory"; then | ||
echo "Skipped database raises error, as it should be!" | ||
else | ||
echo "Skipped database responses unexpectedly" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.