diff --git a/bindata/etcd/cluster-backup.sh b/bindata/etcd/cluster-backup.sh index 0ea57513b5..f22f95fc40 100644 --- a/bindata/etcd/cluster-backup.sh +++ b/bindata/etcd/cluster-backup.sh @@ -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}" diff --git a/bindata/etcd/cluster-restore.sh b/bindata/etcd/cluster-restore.sh index 24b03a559a..ecb8fa515d 100644 --- a/bindata/etcd/cluster-restore.sh +++ b/bindata/etcd/cluster-restore.sh @@ -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}" diff --git a/bindata/etcd/etcd-common-tools b/bindata/etcd/etcd-common-tools index a71f8add32..1ee0ebbd2d 100644 --- a/bindata/etcd/etcd-common-tools +++ b/bindata/etcd/etcd-common-tools @@ -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 +} diff --git a/pkg/operator/etcd_assets/bindata.go b/pkg/operator/etcd_assets/bindata.go index a25ef01128..7a6128b7fc 100644 --- a/pkg/operator/etcd_assets/bindata.go +++ b/pkg/operator/etcd_assets/bindata.go @@ -169,6 +169,9 @@ 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}" `) @@ -274,6 +277,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}" @@ -402,6 +409,14 @@ 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 +} `) func etcdEtcdCommonToolsBytes() ([]byte, error) {