resticprofiles-base/scripts/consul

67 lines
1.4 KiB
Text
Raw Permalink Normal View History

2023-12-03 02:09:46 -05:00
#!/bin/bash
restoreDir=/etc/restore
consulDir="/var/backups/consul"
scriptDir="$(dirname "$0")"
2023-12-03 02:09:46 -05:00
readConfig() {
if [[ -r "${scriptDir}/../config/consul_backup.cfg" ]]; then
source "${scriptDir}/../config/consul_backup.cfg"
fi
}
2023-12-03 02:09:46 -05:00
check() {
2023-12-03 02:09:46 -05:00
if [[ -d "$consulDir" ]]; then
echo "Cleaning out old Consul backups..."
rm -f "$consulDir"/* || return 1
else
mkdir -p "$consulDir" | return 1
fi
if [[ -n "$CONSUL_PATH" ]]; then
2023-12-15 10:43:22 -05:00
if [[ -x "${CONSUL_PATH}/consul" ]]; then
echo "Found Consul in $CONSUL_PATH"
else
2023-12-15 10:43:57 -05:00
echo "FATAL: Cannot execute Consul in $CONSUL_PATH"
return 3
fi
else
2023-12-13 13:11:21 -05:00
if ! which consul &>/dev/null; then
echo "Cannot find Consul in PATH"
return 2
fi
if [[ -x "$(which consul)" ]]; then
2023-12-13 13:12:22 -05:00
CONSUL_PATH="$(dirname "$(which consul)")"
echo "Found Consul in $CONSUL_PATH"
else
echo "FATAL: Cannot execute Consul"
return 3
fi
2023-12-03 02:09:46 -05:00
fi
}
hook_before() {
readConfig
check || exit $?
${CONSUL_PATH}/consul snapshot save "$consulDir/consul.snap"
2023-12-03 02:09:46 -05:00
}
hook_after() {
:
2023-12-03 02:09:46 -05:00
}
hook_fail() {
:
}
hook_final() {
:
}
2023-12-03 02:09:46 -05:00
case "$1" in
before) hook_before || exit $?;;
after) hook_after || exit $?;;
fail) hook_fail || exit $?;;
finally) hook_final || exit $?;;
2023-12-03 02:09:46 -05:00
esac