zalando / spilo

Highly available elephant herd: HA PostgreSQL cluster using Docker
Apache License 2.0
1.55k stars 385 forks source link

Default DAYS_TO_RETAIN value #879

Open Lxrdknows77 opened 1 year ago

Lxrdknows77 commented 1 year ago

There is some misleading with that default value for DAYS_TO_RETAIN in postgres_backup.sh:

# leave at least 2 days base backups before creating a new one
[[ "$DAYS_TO_RETAIN" -lt 2 ]] && DAYS_TO_RETAIN=2

As one guy answered in related topic that it was made deliberately:

Since the retention is applied before creating a new backup we wanted to mitigate the chance that everything was removed before the new backup is created.

However the risk still exists if backup is scheduled less than per once a day, then to keep mitigating the occasion of removing all backups the next inequality must hold:

(BACKUP SCHEDULE) / (DAYS_TO_RETAIN ) > 1

Where "BACKUP SCHEDULE "- in days backup schedule.

For example, if backup scheduled per each 3 days (BACKUP SCHEDULE = 3 ) -> then:

3 / DAYS_TO_RETAIN > 1

then 3 > DAYS_TO_RETAIN

So, if DAYS_TO_RETAIN will be set by default (if less) as 2 now, but it's still risky bc in that case backup will be deleted the day before backup created. Thus that inequality mentioned above must always hold.

Is it correct?