0

I have a postgresql database configured with pgbackrest for backups. It retains full backups for 7 days:

[global]
repo1-retention-full-type=time
repo1-retention-full=7

I've set up cron to create a full backup on Sunday with incremental backups each day. This works as expected and removes full backups after the most recent is >7 days old. The actual crontab calls a script that uses the pgbackrest commands, but for simplicity:

0 0 * * 0   root    pgbackrest --type=full backup
0 0 * * 1-6 root    pgbackrest backup

I'm looking to configure pgbackrest up to automatically create full backups every 7 days so I would only need one cron job:

0 0 * * *   root    pgbackrest backup

Is this possible, or will I have to write some bash logic in my script?

4
  • 1
    why not use a cron job for this
    – nbk
    Commented Mar 21 at 0:13
  • @nbk already explained in the question body, it's only 7 sentences long
    – GammaGames
    Commented Mar 21 at 14:17
  • do you have to configure repo1-retention-diff=42 to have diffs in case PITR or you only can do PITR for 1 week and full backups per week ?
    – nbari
    Commented Apr 15 at 17:06
  • 1
    @nbari from what I understand you can pitr from any full backup (provided WALs are available). This was set up only using incremental backups though, to save disk space.
    – GammaGames
    Commented Apr 15 at 17:37

1 Answer 1

0

My solution was to run a bash script in the crontab that checks the day of week:

#!/usr/bin/env bash

BACKUP_TYPE=$1
if [[ -z $BACKUP_TYPE ]]; then
    DOW=$(date +%u)
    # Do a full backup if it's Sunday 
    if [[ $DOW -eq 7 ]]; then
        BACKUP_TYPE="full"
    else
        BACKUP_TYPE=""
    fi
fi

if [[ -z $BACKUP_TYPE ]]; then
    pgbackrest --stanza=stanza backup
else
    pgbackrest --stanza=stanza --type=$BACKUP_TYPE backup
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.