Change snapshot script to honor ETCD_SNAPSHOTS_DIR variable (#23347)

Also fixing unbound variable error for ETCD_SNAPSHOT_HISTORY_LIMIT
in snapshot.sh

Signed-off-by: Brad Klein <bklein@cray.com>
Co-authored-by: Brad Klein <bklein@cray.com>
This commit is contained in:
Brad Klein 2023-02-17 06:48:19 -07:00 committed by GitHub
parent 6b82130d58
commit 0e869e6f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 15 deletions

View File

@ -70,7 +70,8 @@ export ETCD_DATA_DIR="${ETCD_VOLUME_DIR}/data"
export ETCD_CONF_DIR="${ETCD_BASE_DIR}/conf"
export ETCD_TMP_DIR="${ETCD_BASE_DIR}/tmp"
export ETCD_CONF_FILE="${ETCD_CONF_DIR}/etcd.yaml"
export ETCD_SNAPSHOTS_DIR="/snapshots"
export ETCD_SNAPSHOTS_DIR="${ETCD_SNAPSHOTS_DIR:-/snapshots}"
export ETCD_SNAPSHOT_HISTORY_LIMIT="${ETCD_SNAPSHOT_HISTORY_LIMIT:-1}"
export ETCD_INIT_SNAPSHOTS_DIR="${ETCD_INIT_SNAPSHOTS_DIR:-/init-snapshot}"
export ETCD_NEW_MEMBERS_ENV_FILE="${ETCD_DATA_DIR}/new_member_envs"
export PATH="${ETCD_BIN_DIR}:${PATH}"

View File

@ -14,7 +14,7 @@ set -o nounset
# Load etcd environment settings
. /opt/bitnami/scripts/etcd-env.sh
ensure_dir_exists "/snapshots"
ensure_dir_exists "$ETCD_SNAPSHOTS_DIR"
endpoints="$(etcdctl_get_endpoints)"
read -r -a endpoints_array <<< "$(tr ',;' ' ' <<< "$endpoints")"
for e in "${endpoints_array[@]}"; do
@ -24,10 +24,10 @@ for e in "${endpoints_array[@]}"; do
if etcdctl endpoint health "${extra_flags[@]}"; then
info "Snapshotting the keyspace"
current_time="$(date -u "+%Y-%m-%d_%H-%M")"
etcdctl snapshot save "/snapshots/db-${current_time}" "${extra_flags[@]}"
find /snapshots/ -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
etcdctl snapshot save "${ETCD_SNAPSHOTS_DIR}/db-${current_time}" "${extra_flags[@]}"
find "${ETCD_SNAPSHOTS_DIR}/" -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
| sort -r \
| tail -n+$((1 + ETCD_SNAPSHOT_HISTORY_LIMIT)) \
| tail -n+$((1 + ${ETCD_SNAPSHOT_HISTORY_LIMIT})) \
| xargs rm -f
exit 0
else

View File

@ -70,7 +70,8 @@ export ETCD_DATA_DIR="${ETCD_VOLUME_DIR}/data"
export ETCD_CONF_DIR="${ETCD_BASE_DIR}/conf"
export ETCD_TMP_DIR="${ETCD_BASE_DIR}/tmp"
export ETCD_CONF_FILE="${ETCD_CONF_DIR}/etcd.yaml"
export ETCD_SNAPSHOTS_DIR="/snapshots"
export ETCD_SNAPSHOTS_DIR="${ETCD_SNAPSHOTS_DIR:-/snapshots}"
export ETCD_SNAPSHOT_HISTORY_LIMIT="${ETCD_SNAPSHOT_HISTORY_LIMIT:-1}"
export ETCD_INIT_SNAPSHOTS_DIR="${ETCD_INIT_SNAPSHOTS_DIR:-/init-snapshot}"
export ETCD_NEW_MEMBERS_ENV_FILE="${ETCD_DATA_DIR}/new_member_envs"
export PATH="${ETCD_BIN_DIR}:${PATH}"

View File

@ -14,7 +14,7 @@ set -o nounset
# Load etcd environment settings
. /opt/bitnami/scripts/etcd-env.sh
ensure_dir_exists "/snapshots"
ensure_dir_exists "$ETCD_SNAPSHOTS_DIR"
endpoints="$(etcdctl_get_endpoints)"
read -r -a endpoints_array <<< "$(tr ',;' ' ' <<< "$endpoints")"
for e in "${endpoints_array[@]}"; do
@ -24,10 +24,10 @@ for e in "${endpoints_array[@]}"; do
if etcdctl endpoint health "${extra_flags[@]}"; then
info "Snapshotting the keyspace"
current_time="$(date -u "+%Y-%m-%d_%H-%M")"
etcdctl snapshot save "/snapshots/db-${current_time}" "${extra_flags[@]}"
find /snapshots/ -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
etcdctl snapshot save "${ETCD_SNAPSHOTS_DIR}/db-${current_time}" "${extra_flags[@]}"
find "${ETCD_SNAPSHOTS_DIR}/" -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
| sort -r \
| tail -n+$((1 + ETCD_SNAPSHOT_HISTORY_LIMIT)) \
| tail -n+$((1 + ${ETCD_SNAPSHOT_HISTORY_LIMIT})) \
| xargs rm -f
exit 0
else

View File

@ -70,7 +70,8 @@ export ETCD_DATA_DIR="${ETCD_VOLUME_DIR}/data"
export ETCD_CONF_DIR="${ETCD_BASE_DIR}/conf"
export ETCD_TMP_DIR="${ETCD_BASE_DIR}/tmp"
export ETCD_CONF_FILE="${ETCD_CONF_DIR}/etcd.yaml"
export ETCD_SNAPSHOTS_DIR="/snapshots"
export ETCD_SNAPSHOTS_DIR="${ETCD_SNAPSHOTS_DIR:-/snapshots}"
export ETCD_SNAPSHOT_HISTORY_LIMIT="${ETCD_SNAPSHOT_HISTORY_LIMIT:-1}"
export ETCD_INIT_SNAPSHOTS_DIR="${ETCD_INIT_SNAPSHOTS_DIR:-/init-snapshot}"
export ETCD_NEW_MEMBERS_ENV_FILE="${ETCD_DATA_DIR}/new_member_envs"
export PATH="${ETCD_BIN_DIR}:${PATH}"

View File

@ -14,7 +14,7 @@ set -o nounset
# Load etcd environment settings
. /opt/bitnami/scripts/etcd-env.sh
ensure_dir_exists "/snapshots"
ensure_dir_exists "$ETCD_SNAPSHOTS_DIR"
endpoints="$(etcdctl_get_endpoints)"
read -r -a endpoints_array <<< "$(tr ',;' ' ' <<< "$endpoints")"
for e in "${endpoints_array[@]}"; do
@ -24,10 +24,10 @@ for e in "${endpoints_array[@]}"; do
if etcdctl endpoint health "${extra_flags[@]}"; then
info "Snapshotting the keyspace"
current_time="$(date -u "+%Y-%m-%d_%H-%M")"
etcdctl snapshot save "/snapshots/db-${current_time}" "${extra_flags[@]}"
find /snapshots/ -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
etcdctl snapshot save "${ETCD_SNAPSHOTS_DIR}/db-${current_time}" "${extra_flags[@]}"
find "${ETCD_SNAPSHOTS_DIR}/" -maxdepth 1 -type f -name 'db-*' \! -name "db-${current_time}" \
| sort -r \
| tail -n+$((1 + ETCD_SNAPSHOT_HISTORY_LIMIT)) \
| tail -n+$((1 + ${ETCD_SNAPSHOT_HISTORY_LIMIT})) \
| xargs rm -f
exit 0
else