From 8cd5bbc2dc11e4db035c23541edb81ed2dfb1851 Mon Sep 17 00:00:00 2001 From: Apurva Nisal Date: Mon, 8 Jun 2026 00:36:53 +0530 Subject: [PATCH 1/4] =?UTF-8?q?ETCD-704=20=E2=80=94=20cluster-restore.sh:?= =?UTF-8?q?=20move=20extra=20/var/lib/etcd=20files=20to=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When cluster-restore.sh runs the restore-pod path, it moves member/ and revision.json to /var/lib/etcd-backup, deletes etcd_perf*, then exits if anything remains in /var/lib/etcd. Extra files (perf artifacts, stray snapshots, etc.) cause DR restore to fail before the restore pod starts. Add backup_remaining_etcd_data_dir_contents() to move all remaining top-level entries to /var/lib/etcd-backup instead of failing. Fixes: ETCD-704 Related: https://access.redhat.com/solutions/6958920 --- bindata/etcd/cluster-restore.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bindata/etcd/cluster-restore.sh b/bindata/etcd/cluster-restore.sh index 8e36dd7bad..a588224ef8 100644 --- a/bindata/etcd/cluster-restore.sh +++ b/bindata/etcd/cluster-restore.sh @@ -61,6 +61,22 @@ function restore_static_pods() { done } +function backup_remaining_etcd_data_dir_contents() { + local entry base + + shopt -s nullglob dotglob + for entry in "${ETCD_DATA_DIR}"/*; do + base=$(basename "${entry}") + if [ -e "${ETCD_DATA_DIR_BACKUP}/${base}" ]; then + echo "removing previous backup ${ETCD_DATA_DIR_BACKUP}/${base}" + rm -rf "${ETCD_DATA_DIR_BACKUP:?}/${base}" + fi + echo "Moving ${entry} to ${ETCD_DATA_DIR_BACKUP}/" + mv "${entry}" "${ETCD_DATA_DIR_BACKUP}/" + done + shopt -u nullglob dotglob +} + BACKUP_DIR="$1" # shellcheck disable=SC2012 BACKUP_FILE=$(ls -vd "${BACKUP_DIR}"/static_kuberesources*.tar.gz | tail -1) || true @@ -110,14 +126,9 @@ if [ -z "${ETCD_ETCDCTL_RESTORE}" ]; then cp -p "${SNAPSHOT_FILE}" "${ETCD_DATA_DIR_BACKUP}"/snapshot.db # Move the revision.json when it exists [ ! -f "${ETCD_REV_JSON}" ] || mv -f "${ETCD_REV_JSON}" "${ETCD_DATA_DIR_BACKUP}"/revision.json - # removing any fio perf files left behind that could be deleted without problems - rm -f "${ETCD_DATA_DIR}"/etcd_perf* - - # ensure the folder is really empty, otherwise the restore pod will crash loop - if [ -n "$(ls -A "${ETCD_DATA_DIR}")" ]; then - echo "folder ${ETCD_DATA_DIR} is not empty, please review and remove all files in it" - exit 1 - fi + # Move any remaining files (fio perf artifacts, stray snapshots, etc.) out of the data dir. + # The restore pod requires /var/lib/etcd to be empty before it runs. + backup_remaining_etcd_data_dir_contents echo "starting restore-etcd static pod" cp -p "${RESTORE_ETCD_POD_YAML}" "${MANIFEST_DIR}/etcd-pod.yaml" From 29d2cdd74b7b3d9a73cefb869354daecf6f967c8 Mon Sep 17 00:00:00 2001 From: Apurva Nisal Date: Tue, 9 Jun 2026 23:02:36 +0530 Subject: [PATCH 2/4] ETCD-704: move extra etcd data dir files to backup subdirectory Move leftover /var/lib/etcd entries to extra-data-dir-contents/ so staged snapshot.db, revision.json, and member/ are not overwritten. Co-authored-by: Cursor --- bindata/etcd/cluster-restore.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bindata/etcd/cluster-restore.sh b/bindata/etcd/cluster-restore.sh index a588224ef8..468ab6f7ad 100644 --- a/bindata/etcd/cluster-restore.sh +++ b/bindata/etcd/cluster-restore.sh @@ -62,17 +62,19 @@ function restore_static_pods() { } function backup_remaining_etcd_data_dir_contents() { - local entry base + local entry base extras_dir="${ETCD_DATA_DIR_BACKUP}/extra-data-dir-contents" + + mkdir -p "${extras_dir}" shopt -s nullglob dotglob for entry in "${ETCD_DATA_DIR}"/*; do base=$(basename "${entry}") - if [ -e "${ETCD_DATA_DIR_BACKUP}/${base}" ]; then - echo "removing previous backup ${ETCD_DATA_DIR_BACKUP}/${base}" - rm -rf "${ETCD_DATA_DIR_BACKUP:?}/${base}" + if [ -e "${extras_dir}/${base}" ]; then + echo "removing previous backup ${extras_dir}/${base}" + rm -rf "${extras_dir:?}/${base}" fi - echo "Moving ${entry} to ${ETCD_DATA_DIR_BACKUP}/" - mv "${entry}" "${ETCD_DATA_DIR_BACKUP}/" + echo "Moving ${entry} to ${extras_dir}/" + mv "${entry}" "${extras_dir}/" done shopt -u nullglob dotglob } From bd47518facfc4fd64a9b439af0011157ade1b46c Mon Sep 17 00:00:00 2001 From: Apurva Nisal Date: Thu, 11 Jun 2026 20:02:52 +0530 Subject: [PATCH 3/4] ETCD-704: move backup helper to etcd-common-tools Share backup_remaining_etcd_data_dir_contents via etcd-common-tools per review feedback. Behavior unchanged. --- bindata/etcd/cluster-restore.sh | 18 ------------------ bindata/etcd/etcd-common-tools | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bindata/etcd/cluster-restore.sh b/bindata/etcd/cluster-restore.sh index 468ab6f7ad..962a5610b3 100644 --- a/bindata/etcd/cluster-restore.sh +++ b/bindata/etcd/cluster-restore.sh @@ -61,24 +61,6 @@ function restore_static_pods() { done } -function backup_remaining_etcd_data_dir_contents() { - local entry base extras_dir="${ETCD_DATA_DIR_BACKUP}/extra-data-dir-contents" - - mkdir -p "${extras_dir}" - - shopt -s nullglob dotglob - for entry in "${ETCD_DATA_DIR}"/*; do - base=$(basename "${entry}") - if [ -e "${extras_dir}/${base}" ]; then - echo "removing previous backup ${extras_dir}/${base}" - rm -rf "${extras_dir:?}/${base}" - fi - echo "Moving ${entry} to ${extras_dir}/" - mv "${entry}" "${extras_dir}/" - done - shopt -u nullglob dotglob -} - BACKUP_DIR="$1" # shellcheck disable=SC2012 BACKUP_FILE=$(ls -vd "${BACKUP_DIR}"/static_kuberesources*.tar.gz | tail -1) || true diff --git a/bindata/etcd/etcd-common-tools b/bindata/etcd/etcd-common-tools index 99bf470f1e..f3c36da647 100644 --- a/bindata/etcd/etcd-common-tools +++ b/bindata/etcd/etcd-common-tools @@ -78,6 +78,24 @@ function wait_for_containers_to_stop() { done } +function backup_remaining_etcd_data_dir_contents() { + local entry base extras_dir="${ETCD_DATA_DIR_BACKUP}/extra-data-dir-contents" + + mkdir -p "${extras_dir}" + + shopt -s nullglob dotglob + for entry in "${ETCD_DATA_DIR}"/*; do + base=$(basename "${entry}") + if [ -e "${extras_dir}/${base}" ]; then + echo "removing previous backup ${extras_dir}/${base}" + rm -rf "${extras_dir:?}/${base}" + fi + echo "Moving ${entry} to ${extras_dir}/" + mv "${entry}" "${extras_dir}/" + done + shopt -u nullglob dotglob +} + function mv_static_pods() { local containers=("$@") From 04434a0b6d9b326a91848fbd3234214ce539ba88 Mon Sep 17 00:00:00 2001 From: Apurva Nisal Date: Fri, 12 Jun 2026 18:06:41 +0530 Subject: [PATCH 4/4] ETCD-704: backup extra data dir contents in cluster-restore-tnf.sh Call backup_remaining_etcd_data_dir_contents before rm -rf so leftover files are moved to extra-data-dir-contents/ instead of deleted. --- bindata/etcd/cluster-restore-tnf.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindata/etcd/cluster-restore-tnf.sh b/bindata/etcd/cluster-restore-tnf.sh index 63074cd342..a0e5737d5d 100644 --- a/bindata/etcd/cluster-restore-tnf.sh +++ b/bindata/etcd/cluster-restore-tnf.sh @@ -196,6 +196,9 @@ if [ -d "${ETCD_DATA_DIR}/member" ]; then mv "${ETCD_DATA_DIR}"/member "${ETCD_DATA_DIR_BACKUP}"/ fi +# Move any remaining files out of the data dir before wiping it. +backup_remaining_etcd_data_dir_contents + echo "removing etcd data dir..." rm -rf "${ETCD_DATA_DIR}" mkdir -p "${ETCD_DATA_DIR}"