Updated consul to take configuration and use /var/backups

This commit is contained in:
Eric Renfro 2023-12-13 13:05:24 -05:00
parent c6d446594d
commit a8585a6d92
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
3 changed files with 42 additions and 8 deletions

View file

@ -1,27 +1,58 @@
#!/bin/bash
restoreDir=/etc/restore
consulDir="$restoreDir/consul"
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
rm -rf "$consulDir" || exit 1
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
mkdir -p "$consulDir" || exit 1
pushd "$restoreDir" || exit 2
check || exit $?
#pushd "$restoreDir" || exit 2
consul snapshot save "$consulDir/consul.snap"
${CONSUL_PATH}/consul snapshot save "$consulDir/consul.snap"
popd || exit 2
#popd || exit 2
}
hook_after() {
rm -rf "$consulDir" || exit 1
:
}
hook_fail() {

View file

@ -0,0 +1,3 @@
# This configuration file is used for providing the path
# to consul's binary.
# Example: CONSUL_PATH=/opt/consul/bin