From a849a6968fcabf4b357b99dba4892f497eed408f Mon Sep 17 00:00:00 2001 From: Jakub Boukal Date: Mon, 6 Nov 2023 20:45:58 +0100 Subject: [PATCH] Add rmbackup script to remove backups from postgres/backups. Fixes: #4663 (#4664) --- docs/docker-postgres-backups.rst | 8 +++++ .../production/postgres/maintenance/rmbackup | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 {{cookiecutter.project_slug}}/compose/production/postgres/maintenance/rmbackup diff --git a/docs/docker-postgres-backups.rst b/docs/docker-postgres-backups.rst index c40b6fd69b..fdf4460304 100644 --- a/docs/docker-postgres-backups.rst +++ b/docs/docker-postgres-backups.rst @@ -92,7 +92,15 @@ You will see something like :: Backup to Amazon S3 ---------------------------------- + For uploading your backups to Amazon S3 you can use the aws cli container. There is an upload command for uploading the postgres /backups directory recursively and there is a download command for downloading a specific backup. The default S3 environment variables are used. :: $ docker compose -f production.yml run --rm awscli upload $ docker compose -f production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz + +Remove Backup +---------------------------------- + +To remove backup you can use the ``rmbackup`` command. This will remove the backup from the ``/backups`` directory. :: + + $ docker compose -f local.yml exec postgres rmbackup backup_2018_03_13T09_05_07.sql.gz diff --git a/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/rmbackup b/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/rmbackup new file mode 100644 index 0000000000..fdfd20e148 --- /dev/null +++ b/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/rmbackup @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +### Remove a database backup. +### +### Parameters: +### <1> filename of a backup to remove. +### +### Usage: +### $ docker-compose -f .yml (exec |run --rm) postgres rmbackup <1> + + +set -o errexit +set -o pipefail +set -o nounset + + +working_dir="$(dirname ${0})" +source "${working_dir}/_sourced/constants.sh" +source "${working_dir}/_sourced/messages.sh" + + +if [[ -z ${1+x} ]]; then + message_error "Backup filename is not specified yet it is a required parameter. Make sure you provide one and try again." + exit 1 +fi +backup_filename="${BACKUP_DIR_PATH}/${1}" +if [[ ! -f "${backup_filename}" ]]; then + message_error "No backup with the specified filename found. Check out the 'backups' maintenance script output to see if there is one and try again." + exit 1 +fi + +message_welcome "Removing the '${backup_filename}' backup file..." + +rm -r "${backup_filename}" + +message_success "The '${backup_filename}' database backup has been removed."