From c9984c448cc06cdfd871629289fc645a1e31a43d Mon Sep 17 00:00:00 2001 From: Jacob Babor Date: Sun, 19 Jan 2025 12:47:27 -0600 Subject: [PATCH] Minor reworks to how script is structured for better efficiency --- roles/backup/templates/restic-wrapper.sh | 1 - roles/backup/templates/s3backup.sh | 34 ++++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/roles/backup/templates/restic-wrapper.sh b/roles/backup/templates/restic-wrapper.sh index b7a8b2a..12e04e7 100644 --- a/roles/backup/templates/restic-wrapper.sh +++ b/roles/backup/templates/restic-wrapper.sh @@ -2,5 +2,4 @@ exec nice -n 10 restic \ -r "s3:{{ backup_s3_aws_endpoint_url }}/{{ backup_s3_bucket }}/restic" \ -p /opt/restic-password \ - --verbose \ "$@" diff --git a/roles/backup/templates/s3backup.sh b/roles/backup/templates/s3backup.sh index c952ba2..6eaf00e 100644 --- a/roles/backup/templates/s3backup.sh +++ b/roles/backup/templates/s3backup.sh @@ -48,16 +48,18 @@ fi # Helper functions backup() { # Takes a file or directory to backup and backs it up - [ -z "$1" ] && return 1 - - dir="$1" - echo "- $dir" + [ -z "$@" ] && return 1 if command -v restic > /dev/null 2>&1; then + for dir in "$@"; do + echo "- $dir" + done /opt/restic-wrapper \ backup \ - "$dir" + "$@" else + dir="$@" + echo "- $dir" nice -n 10 tar {{ backup_s3backup_tar_args }}{{ backup_s3backup_tar_args_extra }} \ {% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %} --exclude "{{ item }}" \ @@ -88,15 +90,19 @@ if [ -n "${DIRS[*]}" ]; then echo "- {{ item }}" {% endfor %} echo "Will upload resultant backups to {{ backup_s3_bucket }}" - for dir in "${DIRS[@]}"; do - if [ "$dir" == "/data" ]; then - for datadir in "$dir"/*; do - [ -e "$datadir" ] && backup "$datadir" - done - else - backup "$dir" - fi - done + if command -v restic > /dev/null 2>&1; then + backup ${DIRS[*]} + else + for dir in "${DIRS[@]}"; do + if [ "$dir" == "/data" ]; then + for datadir in "$dir"/*; do + [ -e "$datadir" ] && backup "$datadir" + done + else + backup "$dir" + fi + done + fi fi # Dump Postgres DBs, if possible