Skip to content

Commit a849a69

Browse files
authored
Add rmbackup script to remove backups from postgres/backups. Fixes: cookiecutter#4663 (cookiecutter#4664)
1 parent 562887b commit a849a69

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

docs/docker-postgres-backups.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ You will see something like ::
9292

9393
Backup to Amazon S3
9494
----------------------------------
95+
9596
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. ::
9697

9798
$ docker compose -f production.yml run --rm awscli upload
9899
$ docker compose -f production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz
100+
101+
Remove Backup
102+
----------------------------------
103+
104+
To remove backup you can use the ``rmbackup`` command. This will remove the backup from the ``/backups`` directory. ::
105+
106+
$ docker compose -f local.yml exec postgres rmbackup backup_2018_03_13T09_05_07.sql.gz
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
### Remove a database backup.
4+
###
5+
### Parameters:
6+
### <1> filename of a backup to remove.
7+
###
8+
### Usage:
9+
### $ docker-compose -f <environment>.yml (exec |run --rm) postgres rmbackup <1>
10+
11+
12+
set -o errexit
13+
set -o pipefail
14+
set -o nounset
15+
16+
17+
working_dir="$(dirname ${0})"
18+
source "${working_dir}/_sourced/constants.sh"
19+
source "${working_dir}/_sourced/messages.sh"
20+
21+
22+
if [[ -z ${1+x} ]]; then
23+
message_error "Backup filename is not specified yet it is a required parameter. Make sure you provide one and try again."
24+
exit 1
25+
fi
26+
backup_filename="${BACKUP_DIR_PATH}/${1}"
27+
if [[ ! -f "${backup_filename}" ]]; then
28+
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."
29+
exit 1
30+
fi
31+
32+
message_welcome "Removing the '${backup_filename}' backup file..."
33+
34+
rm -r "${backup_filename}"
35+
36+
message_success "The '${backup_filename}' database backup has been removed."

0 commit comments

Comments
 (0)