From a8585a6d92b82918df3d39a07cd1a9cc73c20598 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Wed, 13 Dec 2023 13:05:24 -0500 Subject: [PATCH] Updated consul to take configuration and use /var/backups --- scripts/consul | 47 +++++++++++++++---- templates/config/consul_backup.cfg | 3 ++ .../config/{mysql.cfg => mysql_backup.cfg} | 0 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 templates/config/consul_backup.cfg rename templates/config/{mysql.cfg => mysql_backup.cfg} (100%) diff --git a/scripts/consul b/scripts/consul index c725234..acdc43a 100755 --- a/scripts/consul +++ b/scripts/consul @@ -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() { diff --git a/templates/config/consul_backup.cfg b/templates/config/consul_backup.cfg new file mode 100644 index 0000000..8805a6a --- /dev/null +++ b/templates/config/consul_backup.cfg @@ -0,0 +1,3 @@ +# This configuration file is used for providing the path +# to consul's binary. +# Example: CONSUL_PATH=/opt/consul/bin diff --git a/templates/config/mysql.cfg b/templates/config/mysql_backup.cfg similarity index 100% rename from templates/config/mysql.cfg rename to templates/config/mysql_backup.cfg