Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a CLI option to disable cleanups (with examples)
  • Loading branch information
tdemin committed Jun 10, 2019
1 parent d2e2a0e commit 3ab4884
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions backup.sh
Expand Up @@ -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
}

Expand All @@ -115,6 +116,7 @@ case ${1} in
;;
"-h" | "--help")
print_help
__BACKUP_NO_CLEANUP=1 # prevent cleanup on displaying help
;;
*)
while [[ ! -z ${1} ]]; do
Expand All @@ -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
2 changes: 1 addition & 1 deletion systemd/backup_postgresql.service
Expand Up @@ -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
Expand Down

0 comments on commit 3ab4884

Please sign in to comment.