EnterpriseDB / barman

Barman - Backup and Recovery Manager for PostgreSQL
https://www.pgbarman.org/
GNU General Public License v3.0
2.07k stars 191 forks source link

Restrict the use of keep annotations to full backups only #947

Closed bleidens closed 3 months ago

bleidens commented 3 months ago

An incremental backup with the keep annotation that has its parent deleted would become an orphan backup and therefore useless for recovery. To avoid this, we should restrict the use of keep annotations to full backups only. This adds a new check prior to starting the annotation process to make sure we do not allow keeping a backup if it has a parent backup, raising an error if so.

References: BAR-184

bleidens commented 3 months ago

I decided to add this check to the cli.py file inside the keep command since it also contains other checks and it seems better to make this check before starting an annotation. I also thought about adding this to annotations.py, inside KeepManagerMixin.keep_backup, but I need suggestions about the best place to make this check.

I will also still make updates for the case in which a parent backup exists but is empty, since this would pass the check in the current implementation, adding the keep annotation to the child backup.

bleidens commented 3 months ago

I just finished updating the unit tests and changed the check condition to only consider the existence of backup_info.parent_backup_id, no longer using the get_parent_backup_info method and avoiding passing the check in the case of empty parent backups.