Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.6] Bug 1979585: Validate the status of the etcd snapshot during backup and restore #624

Merged
merged 1 commit into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindata/etcd/cluster-backup.sh
Expand Up @@ -101,4 +101,7 @@ fi
dl_etcdctl
backup_latest_kube_static_resources "${BACKUP_RESOURCE_LIST[@]}"
ETCDCTL_ENDPOINTS="https://${NODE_NODE_ENVVAR_NAME_IP}:2379" etcdctl snapshot save "${SNAPSHOT_FILE}"

# Check the integrity of the snapshot
check_snapshot_status "${SNAPSHOT_FILE}"
echo "snapshot db and kube resources are successfully saved to ${BACKUP_DIR}"
4 changes: 4 additions & 0 deletions bindata/etcd/cluster-restore.sh
Expand Up @@ -85,6 +85,10 @@ if [ ! -d "$MANIFEST_STOPPED_DIR" ]; then
mkdir -p "$MANIFEST_STOPPED_DIR"
fi

# Download etcdctl and check the snapshot status
dl_etcdctl
check_snapshot_status "${SNAPSHOT_FILE}"

# Move static pod manifests out of MANIFEST_DIR
for POD_FILE_NAME in "${STATIC_POD_LIST[@]}" etcd-pod.yaml; do
echo "...stopping ${POD_FILE_NAME}"
Expand Down
8 changes: 8 additions & 0 deletions bindata/etcd/etcd-common-tools
Expand Up @@ -31,3 +31,11 @@ function exec_etcdctl {
fi
crictl exec -it $container_id /bin/sh -c "etcdctl $command"
}

function check_snapshot_status() {
local snap_file="$1"
if ! etcdctl snapshot status "${snap_file}" -w json; then
echo "Backup integrity verification failed. Backup appears corrupted. Aborting!"
return 1
fi
}
15 changes: 15 additions & 0 deletions pkg/operator/etcd_assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.