From 3ab4884c8cdc255992b9e1a5c38fa0addc562a18 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Mon, 10 Jun 2019 17:53:12 +0500 Subject: [PATCH] Add a CLI option to disable cleanups (with examples) --- README.md | 1 + backup.sh | 19 +++++++++++++------ systemd/backup_postgresql.service | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7b93868..00dd101 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ It comes with example systemd units/timers made to do just that. -p | --postgres: run the backups on PostgreSQL databases -d | --docker: run the backups on Docker volumes -c | --configs: run the backups on the files specified in /etc/backups.conf + --no-cleanup: don't cleanup after the backup has finished ##### Configuration options diff --git a/backup.sh b/backup.sh index bcb3f1b..894fbf6 100644 --- a/backup.sh +++ b/backup.sh @@ -102,6 +102,7 @@ Options: -p | --postgres: run the backups on PostgreSQL databases -d | --docker: run the backups on Docker volumes -c | --configs: run the backups on the files specified in /etc/backups.conf +--no-cleanup: don't cleanup after the backup has finished EOF } @@ -115,6 +116,7 @@ case ${1} in ;; "-h" | "--help") print_help + __BACKUP_NO_CLEANUP=1 # prevent cleanup on displaying help ;; *) while [[ ! -z ${1} ]]; do @@ -128,15 +130,20 @@ case ${1} in "-c" | "--configs") backup_configs ;; + "--no-cleanup") + __BACKUP_NO_CLEANUP=1 + ;; esac shift done ;; esac -echo "Cleaning up..." -# Run cleanup on every backup directory. -for i in ${__BACKUP_DIR} ${__BACKUP_DIR_CONFIGS} ${__BACKUP_DIR_DOCKER} \ - ${__BACKUP_DIR_POSTGRES}; do - [[ ! -z $i ]] && clean_up $i -done +if [[ -z ${__BACKUP_NO_CLEANUP} ]]; then + echo "Cleaning up..." + # Run cleanup on every backup directory. + for i in ${__BACKUP_DIR} ${__BACKUP_DIR_CONFIGS} ${__BACKUP_DIR_DOCKER} \ + ${__BACKUP_DIR_POSTGRES}; do + [[ ! -z $i ]] && clean_up $i + done +fi diff --git a/systemd/backup_postgresql.service b/systemd/backup_postgresql.service index 1cc8e1d..17fd195 100644 --- a/systemd/backup_postgresql.service +++ b/systemd/backup_postgresql.service @@ -3,7 +3,7 @@ Description=Run backups on PostgreSQL databases [Service] Type=oneshot -ExecStart=/usr/local/bin/backup.sh -p +ExecStart=/usr/local/bin/backup.sh -p --no-cleanup User=postgres Group=postgres WorkingDirectory=/tmp