2023-12-03 02:09:46 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
restoreDir=/etc/restore
|
2023-12-13 13:05:24 -05:00
|
|
|
consulDir="/var/backups/consul"
|
|
|
|
scriptDir="$(dirname "$0")"
|
2023-12-03 02:09:46 -05:00
|
|
|
|
2023-12-13 13:05:24 -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
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
check() {
|
2023-12-03 02:09:46 -05:00
|
|
|
if [[ -d "$consulDir" ]]; then
|
2023-12-13 13:05:24 -05:00
|
|
|
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
|
2023-12-13 13:05:24 -05:00
|
|
|
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)")"
|
2023-12-13 13:05:24 -05:00
|
|
|
echo "Found Consul in $CONSUL_PATH"
|
|
|
|
else
|
|
|
|
echo "FATAL: Cannot execute Consul"
|
|
|
|
return 3
|
|
|
|
fi
|
2023-12-03 02:09:46 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_before() {
|
2023-12-13 13:05:24 -05:00
|
|
|
check || exit $?
|
|
|
|
#pushd "$restoreDir" || exit 2
|
2023-12-03 02:09:46 -05:00
|
|
|
|
2023-12-13 13:05:24 -05:00
|
|
|
${CONSUL_PATH}/consul snapshot save "$consulDir/consul.snap"
|
2023-12-03 02:09:46 -05:00
|
|
|
|
2023-12-13 13:05:24 -05:00
|
|
|
#popd || exit 2
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_after() {
|
2023-12-13 13:05:24 -05:00
|
|
|
:
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_fail() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_final() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2023-12-03 02:09:46 -05:00
|
|
|
case "$1" in
|
2023-12-03 06:44:35 -05:00
|
|
|
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
|