forked from cookiecutter/cookiecutter-django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rmbackup script to remove backups from postgres/backups. Fixes: c…
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/rmbackup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
### Remove a database backup. | ||
### | ||
### Parameters: | ||
### <1> filename of a backup to remove. | ||
### | ||
### Usage: | ||
### $ docker-compose -f <environment>.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." |