bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
8.81k stars 9.1k forks source link

[bitnami/postgresql] Set the number of backups to keep #27954

Closed joaopedrocg27 closed 1 month ago

joaopedrocg27 commented 1 month ago

Name and Version

bitnami/postgresql 15.5.14

What is the problem this feature will solve?

This would save a lot of disk space.

What is the feature you are proposing to solve the problem?

I would like to set the maximum number of backups using the backup feature so I do not keep an infinite number of pgdump files.

What alternatives have you considered?

I have tried this and it works great but it would be great if it was integrated in the chart:

      command:
      - /bin/sh
      - -c
      - |
        BACKUP_DIR=${PGDUMP_DIR}
        BACKUPS_TO_KEEP=5

        echo "Current backups in ${BACKUP_DIR}:"
        ls -lh ${BACKUP_DIR}/pg_dumpall-*.pgdump

        pg_dumpall --clean --if-exists --load-via-partition-root --quote-all-identifiers --no-password --file=${BACKUP_DIR}/pg_dumpall-$(date '+%Y-%m-%d-%H-%M').pgdump

        if [ $? -eq 0 ]; then
          echo "Backup created successfully."

          BACKUPS_TO_DELETE=$(ls -1t $BACKUP_DIR/pg_dumpall-*.pgdump | tail -n +$((BACKUPS_TO_KEEP+1)))

          if [ -n "$BACKUPS_TO_DELETE" ]; then
            echo "Deleting old backups:"
            echo "$BACKUPS_TO_DELETE"

            echo "$BACKUPS_TO_DELETE" | xargs -I {} rm -- {}
          else
            echo "No backups to delete."
          fi
        else
          echo "Backup creation failed. Old backups will not be deleted."
        fi

Before and After

image image

Logs (other deployment):

image
javsalgar commented 1 month ago

Hi!

Thanks for the feature request. I imagine this could be implemented as some sort of job that accesses the database. Would you like to propose a PR?

joaopedrocg27 commented 1 month ago

Hi!

Thanks for the feature request. I imagine this could be implemented as some sort of job that accesses the database. Would you like to propose a PR?

Could this just replace the current default for the backup command that runs as a cron job? I opened this fr because I thought that nobody faced this yet.

I'll open a PR when I find some free time. Thank you

github-actions[bot] commented 1 month ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 1 month ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.