Skip to content

Commit 444838e

Browse files
author
Matthew Fisher
committed
feat(charts): add backup to preStop hook
1 parent 6fac0b1 commit 444838e

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

charts/database/templates/database-deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ spec:
4545
exec:
4646
command:
4747
- is_running
48+
lifecycle:
49+
preStop:
50+
exec:
51+
commmand:
52+
- gosu
53+
- postgres
54+
- do_backup
4855
initialDelaySeconds: 30
4956
timeoutSeconds: 1
5057
volumeMounts:

rootfs/bin/backup

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
#!/usr/bin/env bash
22

33
export BACKUP_FREQUENCY=${BACKUP_FREQUENCY:-4h}
4-
export BACKUPS_TO_RETAIN=${BACKUPS_TO_RETAIN:-5}
54

65
while true; do
76
sleep "$BACKUP_FREQUENCY"
8-
echo "Performing a base backup..."
9-
if [[ -f "$PGDATA/recovery.conf" ]] ; then
10-
echo "Database is currently recovering from a backup. Will try again next loop..."
11-
else
12-
# perform a backup
13-
envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
14-
# only retain the latest BACKUPS_TO_RETAIN backups
15-
envdir "$WALE_ENVDIR" wal-e delete --confirm retain "$BACKUPS_TO_RETAIN"
16-
echo "Backup has been completed."
17-
fi
7+
do_backup
188
done

rootfs/bin/do_backup

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
export BACKUPS_TO_RETAIN=${BACKUPS_TO_RETAIN:-5}
4+
5+
echo "Performing a base backup..."
6+
if [[ -f "$PGDATA/recovery.conf" ]] ; then
7+
echo "Database is currently recovering from a backup. Aborting"
8+
else
9+
# perform a backup
10+
envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
11+
# only retain the latest BACKUPS_TO_RETAIN backups
12+
envdir "$WALE_ENVDIR" wal-e delete --confirm retain "$BACKUPS_TO_RETAIN"
13+
echo "Backup has been completed."
14+
fi

0 commit comments

Comments
 (0)