Skip to content

Commit efbc240

Browse files
authored
PG backup limit table data storage (#174)
Some tables from HDS do not need to have their data included in the backups. This change will support excluding certain tables from the backup.
1 parent 3a1d719 commit efbc240

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

containers/tools/pgbackup/pgsync.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ if ! [ -x "$(command -v gpg)" ]; then
1616
exit 1
1717
fi
1818

19+
# This function will expect the `PG_EXCLUDE_TABLE_DATA_TABLES` argument to carry a
20+
# comma-separated list of tables. These are then split up into arguments for use
21+
# with `pg_dump`.
22+
23+
function pg_exclude_table_data_args()
24+
{
25+
local table_patterns
26+
27+
IFS=',' read -r -a table_patterns <<< "${PG_EXCLUDE_TABLE_DATA_TABLES}"
28+
29+
for table in "${table_patterns[@]}"; do
30+
echo -n " --exclude-table-data ${table}"
31+
done
32+
}
33+
1934
ACTION="$1"
2035
PG_DBNAME="$2"
2136

@@ -49,7 +64,7 @@ fi
4964

5065
# Database config
5166
if [ -z "$PG_HOSTNAME" ]; then
52-
echo "Please set TWOBUCKET!"
67+
echo "Please set PG_HOSTNAME!"
5368
exit 1
5469
fi
5570
if [ -z "$PG_PORT" ]; then
@@ -85,16 +100,16 @@ case $ACTION in
85100
echo "Backup ${PG_DBNAME} to ${REMOTE}/$SNAPSHOT_NAME..."
86101
cd /tmp
87102
export XZ_DEFAULTS="-2"
88-
pg_dump -C -h $PG_HOSTNAME -p $PG_PORT -d $PG_DBNAME -U $PG_USERNAME | xz > /tmp/$SNAPSHOT_NAME
103+
pg_dump -C -h "${PG_HOSTNAME}" -p "${PG_PORT}" -d "${PG_DBNAME}" -U "${PG_USERNAME}" $(pg_exclude_table_data_args) | xz > "/tmp/${SNAPSHOT_NAME}"
89104
if [[ $? -ne 0 ]]; then
90105
rm -f ~/.pgpass
91-
echo "Error: Problem encounted performing snapshot!"
106+
echo "Error: Problem encountered performing snapshot!"
92107
exit 1
93108
fi
94109
rm -f ~/.pgpass
95110
cat $TWOSECRET_PATH | gpg --batch --yes --passphrase-fd 0 --symmetric --cipher-algo TWOFISH /tmp/$SNAPSHOT_NAME
96111
if [[ $? -ne 0 ]]; then
97-
echo "Error: Problem encounted performing encryption! (gpg)"
112+
echo "Error: Problem encountered performing encryption! (gpg)"
98113
rm /tmp/$SNAPSHOT_NAME
99114
exit 1
100115
fi
@@ -118,21 +133,21 @@ case $ACTION in
118133
rclone copy $REMOTE/$LATEST /tmp/
119134
if [[ $? -ne 0 ]]; then
120135
rm -f ~/.pgpass
121-
echo "Error: Problem encounted getting snapshot from s3! (mc)"
136+
echo "Error: Problem encountered getting snapshot from s3! (mc)"
122137
rm /tmp/$LATEST
123138
exit 1
124139
fi
125140
echo $TWOSECRET | gpg --batch --yes --passphrase-fd 0 -o /tmp/$PG_DBNAME-restore.sql.xz -d /tmp/$LATEST
126141
if [[ $? -ne 0 ]]; then
127-
echo "Error: Problem encounted decrypting snapshot! (gpg)"
142+
echo "Error: Problem encountered decrypting snapshot! (gpg)"
128143
rm -f ~/.pgpass
129144
rm /tmp/$LATEST
130145
exit 1
131146
fi
132147
rm /tmp/$LATEST
133148
xz -cd /tmp/$PG_DBNAME-restore.sql.xz | psql -h $PG_HOSTNAME -U $PG_USERNAME
134149
if [[ $? -ne 0 ]]; then
135-
echo "Error: Problem encounted extracting snapshot! (sql)"
150+
echo "Error: Problem encountered extracting snapshot! (sql)"
136151
rm -f ~/.pgpass
137152
rm /tmp/$PG_DBNAME-restore.sql.xz
138153
exit 1

deployments/haikudepotserver.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ spec:
210210
secretKeyRef:
211211
name: postgres-admin
212212
key: password
213+
# Some tables' data is transient and so in a recovery situation does not need to be
214+
# recovered. To save on backup overhead these tables are skipped.
215+
- name: PG_EXCLUDE_TABLE_DATA_TABLES
216+
value: "job.job*data,job.job_state,job.job_specification,job.job,datastore.*"
213217
volumeMounts:
214218
- name: rclone-config
215219
mountPath: /root/.config

0 commit comments

Comments
 (0)