resticprofiles-base/scripts/consul

70 lines
1.4 KiB
Text
Raw 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
if [[ -x "${CONSUL_PATH/consul}" ]]; then
echo "Found Consul in $CONSUL_PATH"
else
echo "FATAL: Cannot execute Consul"
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:11:21 -05:00
CONSUL_PATH="$(basename "$(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() {
check || exit $?
#pushd "$restoreDir" || exit 2
2023-12-03 02:09:46 -05:00
${CONSUL_PATH}/consul snapshot save "$consulDir/consul.snap"
2023-12-03 02:09:46 -05:00
#popd || exit 2
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