mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 13:51:35 +01:00
63 lines
1.6 KiB
Django/Jinja
63 lines
1.6 KiB
Django/Jinja
#!/bin/bash
|
|
set -eu
|
|
|
|
mkdir -p {{ hostname_base }}
|
|
cd {{ hostname_base }}
|
|
|
|
if [ $# -ne 0 ]; then
|
|
TYPE=$1
|
|
fi
|
|
|
|
TEST=$(python3 -c "print(int('$TYPE' in ['size_changed', 'no_high_data', 'minimal', ''])^1)")
|
|
if [ $TEST -ne 0 ]; then
|
|
echo Bad Filter Option [$TYPE]
|
|
exit 1
|
|
fi
|
|
|
|
dest=./
|
|
for x in backup-*; do
|
|
test -d "$x" || continue
|
|
dest="../$x" # relative to destination directory
|
|
done
|
|
|
|
target="backup-$(date '+%Y-%m-%d-%H-%M-%S')"
|
|
target_tmp="partial-$target"
|
|
|
|
mkdir "$target_tmp"
|
|
|
|
rsync \
|
|
--verbose --itemize-changes --human-readable \
|
|
--archive --acls --xattrs --hard-links --sparse --numeric-ids \
|
|
--one-file-system \
|
|
--link-dest="$dest" \
|
|
--filter="merge ../rsync-filter-{{ hostname_base }}-${TYPE}.txt" \
|
|
root@{{ hostname }}:/ \
|
|
"$target_tmp"
|
|
|
|
RSYNC_SUCCESS=$?
|
|
|
|
mv "$target_tmp" "$target"
|
|
|
|
CONTENT_TYPE="Content-Type: application/json"
|
|
ASYNC_ICINGA_ADDRESS="https://async-icinga.atlantishq.de/"
|
|
SERVICE="backup_{{ hostname_base }}"
|
|
TOKEN="{{ token }}"
|
|
|
|
if [ $RSYNC_SUCCESS -eq 0 ]; then
|
|
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
|
"{\"service\": \"${SERVICE}\", \"token\": \"${TOKEN}\", \"status\": \"OK\", \"info\": \"\"}"
|
|
|
|
# if size changed was copied save new size #
|
|
{% if not size_change_commands %}
|
|
echo No Sizes to notifiy
|
|
{% endif %}
|
|
{% for cmd in size_change_commands %}
|
|
{{ cmd }}
|
|
{% endfor %}
|
|
else
|
|
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
|
"{\"service\": \"${SERVICE}\", \"token\": \"${TOKEN}\", \"status\": \"CRITICAL\", \"info\": \"\"}"
|
|
fi
|
|
|
|
cd ..
|