Postgresql – barman + backup and restore + how to enable auto deletion from backup files

backupbarmanlinuxpostgresql

I am using the barman tool to backup the postgresql DB

barman is working fine but I notice that backup files that created under
/var/lib/barman/main-db-server/base folder are not automatically being deleted after so many days.

I found the variable last_backup_maximum_age – but this only for reporting

 last_backup_maximum_age
 This option identifies a time frame that must contain the latest backup. If 
 the latest backup is older than the time frame, barman check command will 
 report an error to the user. If empty (default), latest backup is always 
 considered valid. Syntax for this option is: “i (DAYS | WEEKS | MONTHS)” 
 where i is a integer greater than zero, representing the number of days | 
 weeks | months of the time frame. Global/Server.

I can use

barman delete <server_name> oldest 

in order to delete every time the oldest file; however, I want to understand if I've missed something that can automatically delete the files once they reach a certain age; an auto-rotate or auto-delete functionality.

Best Answer

You should configure retention_policy.

Here's the syntax :

retention_policy = {REDUNDANCY value | RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}}

You will find documentation here