mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 22:01:35 +01:00
fix: backup management
This commit is contained in:
24
backup.py
24
backup.py
@@ -38,6 +38,10 @@ def createBackupScriptStructure(backupList, baseDomain=""):
|
|||||||
pathsToOptions = dict()
|
pathsToOptions = dict()
|
||||||
basePaths = []
|
basePaths = []
|
||||||
fullPaths = []
|
fullPaths = []
|
||||||
|
|
||||||
|
# commands for all size changed paths #
|
||||||
|
sizeChangeNotifyCommands = []
|
||||||
|
|
||||||
for p in paths:
|
for p in paths:
|
||||||
|
|
||||||
cur = p
|
cur = p
|
||||||
@@ -69,6 +73,12 @@ def createBackupScriptStructure(backupList, baseDomain=""):
|
|||||||
fullPaths.append(cur)
|
fullPaths.append(cur)
|
||||||
pathsToOptions.update({ "{}\t{}".format(hostname, cur) : options })
|
pathsToOptions.update({ "{}\t{}".format(hostname, cur) : options })
|
||||||
|
|
||||||
|
# build commands to save new size after backup #
|
||||||
|
if options and "onlyifsizechanged" in options:
|
||||||
|
cmd = "ssh {} -t /opt/check_dir_size_for_backup.py --save-new-size {}"
|
||||||
|
cmd = cmd.format(hostname, cur)
|
||||||
|
sizeChangeNotifyCommands.append(cmd)
|
||||||
|
|
||||||
# keep order (important!)
|
# keep order (important!)
|
||||||
pathsAll = list(set(basePaths)) + [ p.rstrip("/") + "/***" for p in fullPaths ]
|
pathsAll = list(set(basePaths)) + [ p.rstrip("/") + "/***" for p in fullPaths ]
|
||||||
|
|
||||||
@@ -82,11 +92,19 @@ def createBackupScriptStructure(backupList, baseDomain=""):
|
|||||||
pathsMinimal = list(filter(filterSizeChanged, pathsNoHighData))
|
pathsMinimal = list(filter(filterSizeChanged, pathsNoHighData))
|
||||||
|
|
||||||
rsyncScript = rsyncScriptTemplate.render(hostname=hostname, token=icingaToken,
|
rsyncScript = rsyncScriptTemplate.render(hostname=hostname, token=icingaToken,
|
||||||
hostname_base=hostnameBase)
|
hostname_base=hostnameBase,
|
||||||
|
size_change_commands=sizeChangeNotifyCommands)
|
||||||
|
|
||||||
|
# build all filter #
|
||||||
rsyncFilterAll = rsyncFilterTemplate.render(paths=pathsAll)
|
rsyncFilterAll = rsyncFilterTemplate.render(paths=pathsAll)
|
||||||
|
|
||||||
|
# build filter excluding high data #
|
||||||
rsyncFilterNoHighData = rsyncFilterTemplate.render(paths=pathsNoHighData)
|
rsyncFilterNoHighData = rsyncFilterTemplate.render(paths=pathsNoHighData)
|
||||||
|
|
||||||
|
# build filter excluding size changed no #
|
||||||
rsyncFilterOnlyIfSizeChanged = rsyncFilterTemplate.render(paths=pathsOnlyIfSizeChanged)
|
rsyncFilterOnlyIfSizeChanged = rsyncFilterTemplate.render(paths=pathsOnlyIfSizeChanged)
|
||||||
|
|
||||||
|
# build filter without high data and without non-size-changed dirs #
|
||||||
rsyncFilterMinimal = rsyncFilterTemplate.render(paths=pathsMinimal)
|
rsyncFilterMinimal = rsyncFilterTemplate.render(paths=pathsMinimal)
|
||||||
|
|
||||||
# async icinga config #
|
# async icinga config #
|
||||||
@@ -123,7 +141,7 @@ def createBackupScriptStructure(backupList, baseDomain=""):
|
|||||||
wrapperName = "wrapper.sh"
|
wrapperName = "wrapper.sh"
|
||||||
with open(os.path.join(backupPath, wrapperName), "w") as f:
|
with open(os.path.join(backupPath, wrapperName), "w") as f:
|
||||||
for n in scriptNames:
|
for n in scriptNames:
|
||||||
f.write("./{}".format(n))
|
f.write("./{} $1".format(n))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
os.chmod(os.path.join(backupPath, wrapperName), 0o700)
|
os.chmod(os.path.join(backupPath, wrapperName), 0o700)
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ set -eu
|
|||||||
mkdir -p {{ hostname_base }}
|
mkdir -p {{ hostname_base }}
|
||||||
cd {{ hostname_base }}
|
cd {{ hostname_base }}
|
||||||
|
|
||||||
TYPE=""
|
if [ $# -ne 0 ]; then
|
||||||
if [ -z "$1" ]; then
|
|
||||||
TYPE=$1
|
TYPE=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEST=$(python -c "int('$TYPE' in ['size_changed', 'no_high_data', 'minimal'])^1")
|
TEST=$(python3 -c "print(int('$TYPE' in ['size_changed', 'no_high_data', 'minimal', ''])^1)")
|
||||||
if [ $TEST -ne 0 ]; then
|
if [ $TEST -ne 0 ]; then
|
||||||
echo Bad Filter Option $1
|
echo Bad Filter Option [$TYPE]
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dest=./
|
dest=./
|
||||||
@@ -46,6 +46,14 @@ TOKEN="{{ token }}"
|
|||||||
if [ $RSYNC_SUCCESS -eq 0 ]; then
|
if [ $RSYNC_SUCCESS -eq 0 ]; then
|
||||||
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
||||||
"{\"service\": \"${SERVICE}\", \"token\": \"${TOKEN}\", \"status\": \"OK\", \"info\": \"\"}"
|
"{\"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
|
else
|
||||||
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
curl -H "${CONTENT_TYPE}" -X POST "${ASYNC_ICINGA_ADDRESS}" -d \
|
||||||
"{\"service\": \"${SERVICE}\", \"token\": \"${TOKEN}\", \"status\": \"CRITICAL\", \"info\": \"\"}"
|
"{\"service\": \"${SERVICE}\", \"token\": \"${TOKEN}\", \"status\": \"CRITICAL\", \"info\": \"\"}"
|
||||||
|
|||||||
Reference in New Issue
Block a user