Minor reworks to how script is structured for better efficiency

This commit is contained in:
Salt 2025-01-19 12:47:27 -06:00
parent f3520c10ae
commit c9984c448c
2 changed files with 20 additions and 15 deletions

View File

@ -2,5 +2,4 @@
exec nice -n 10 restic \ exec nice -n 10 restic \
-r "s3:{{ backup_s3_aws_endpoint_url }}/{{ backup_s3_bucket }}/restic" \ -r "s3:{{ backup_s3_aws_endpoint_url }}/{{ backup_s3_bucket }}/restic" \
-p /opt/restic-password \ -p /opt/restic-password \
--verbose \
"$@" "$@"

View File

@ -48,16 +48,18 @@ fi
# Helper functions # Helper functions
backup() { backup() {
# Takes a file or directory to backup and backs it up # Takes a file or directory to backup and backs it up
[ -z "$1" ] && return 1 [ -z "$@" ] && return 1
dir="$1"
echo "- $dir"
if command -v restic > /dev/null 2>&1; then if command -v restic > /dev/null 2>&1; then
for dir in "$@"; do
echo "- $dir"
done
/opt/restic-wrapper \ /opt/restic-wrapper \
backup \ backup \
"$dir" "$@"
else else
dir="$@"
echo "- $dir"
nice -n 10 tar {{ backup_s3backup_tar_args }}{{ backup_s3backup_tar_args_extra }} \ 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 %} {% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %}
--exclude "{{ item }}" \ --exclude "{{ item }}" \
@ -88,6 +90,9 @@ if [ -n "${DIRS[*]}" ]; then
echo "- {{ item }}" echo "- {{ item }}"
{% endfor %} {% endfor %}
echo "Will upload resultant backups to {{ backup_s3_bucket }}" echo "Will upload resultant backups to {{ backup_s3_bucket }}"
if command -v restic > /dev/null 2>&1; then
backup ${DIRS[*]}
else
for dir in "${DIRS[@]}"; do for dir in "${DIRS[@]}"; do
if [ "$dir" == "/data" ]; then if [ "$dir" == "/data" ]; then
for datadir in "$dir"/*; do for datadir in "$dir"/*; do
@ -98,6 +103,7 @@ if [ -n "${DIRS[*]}" ]; then
fi fi
done done
fi fi
fi
# Dump Postgres DBs, if possible # Dump Postgres DBs, if possible
if command -v psql > /dev/null 2>&1; then if command -v psql > /dev/null 2>&1; then