resticprofiles-base/scripts/consul

71 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
restoreDir=/etc/restore
consulDir="/var/backups/consul"
scriptDir="$(dirname "$0")"
readConfig() {
local $config
if [[ -r "${scriptDir}/../config/consul_backup.cfg" ]]; then
source "${scriptDir}/../config/consul_backup.cfg"
fi
}
check() {
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
if ! which consul; then
echo "Cannot find Consul in PATH"
return 2
fi
if [[ -x "$(which consul)" ]]; then
CONSUL_PATH="$(basename 'which consul')"
echo "Found Consul in $CONSUL_PATH"
else
echo "FATAL: Cannot execute Consul"
return 3
fi
fi
}
hook_before() {
check || exit $?
#pushd "$restoreDir" || exit 2
${CONSUL_PATH}/consul snapshot save "$consulDir/consul.snap"
#popd || exit 2
}
hook_after() {
:
}
hook_fail() {
:
}
hook_final() {
:
}
case "$1" in
before) hook_before || exit $?;;
after) hook_after || exit $?;;
fail) hook_fail || exit $?;;
finally) hook_final || exit $?;;
esac