Skip to content

Commit db4cd9d

Browse files
author
Matthew Fisher
committed
fix(rootfs): always perform an initial backup
When you complete a recovery of the database for the first time, a new log timeline is started with an ID of 2. When you restore again (timeline of 3), the timeline used when the last backup occurred will be replayed. Because of this, if you restored the database and did not perform a backup, all data committed after that successful recovery will be lost because only WAL logs from the first timeline (the timeline that the database was last backed up) will be restored. In order to fix this, after completing a database recovery we create a fresh backup in order to establish a new recovery baseline. That way we can now replay from timeline 2.
1 parent f502600 commit db4cd9d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ EOF
4848
-o "-c listen_addresses=''" \
4949
-t 1200 \
5050
-w start
51-
else
52-
echo "No backups found. Performing an initial backup..."
53-
gosu postgres envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
5451
fi
5552

53+
echo "Performing an initial backup..."
54+
gosu postgres envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
55+
5656
# ensure $PGDATA has the right permissions
5757
chown -R postgres:postgres "$PGDATA"
5858
chmod 0700 "$PGDATA"

0 commit comments

Comments
 (0)