From 0e869e6f0f045d1a35682a9893efdd97a2698eaf Mon Sep 17 00:00:00 2001 From: Brad Klein Date: Fri, 17 Feb 2023 06:48:19 -0700 Subject: [PATCH] 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 Co-authored-by: Brad Klein --- .../3.3/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh | 3 ++- .../debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh | 8 ++++---- .../3.4/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh | 3 ++- .../debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh | 8 ++++---- .../3.5/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh | 3 ++- .../debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh | 8 ++++---- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh b/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh index 3c8194bb9774..6590eba00189 100644 --- a/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh +++ b/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh @@ -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}" diff --git a/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh b/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh index c8fd5e7e88a0..3b8808e0e38e 100755 --- a/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh +++ b/bitnami/etcd/3.3/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh @@ -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 diff --git a/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh b/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh index 3c8194bb9774..6590eba00189 100644 --- a/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh +++ b/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh @@ -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}" diff --git a/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh b/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh index c8fd5e7e88a0..3b8808e0e38e 100755 --- a/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh +++ b/bitnami/etcd/3.4/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh @@ -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 diff --git a/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh b/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh index 3c8194bb9774..6590eba00189 100644 --- a/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh +++ b/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd-env.sh @@ -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}" diff --git a/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh b/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh index c8fd5e7e88a0..3b8808e0e38e 100755 --- a/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh +++ b/bitnami/etcd/3.5/debian-11/rootfs/opt/bitnami/scripts/etcd/snapshot.sh @@ -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