-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the disaster recovery scripts
- Loading branch information
retroflexer
committed
Mar 5, 2020
1 parent
80e5b29
commit 0531dc4
Showing
12 changed files
with
321 additions
and
1,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Common environment variables | ||
ASSET_DIR="/home/core/assets" | ||
CONFIG_FILE_DIR="/etc/kubernetes" | ||
MANIFEST_DIR="${CONFIG_FILE_DIR}/manifests" | ||
ETCD_DATA_DIR="/var/lib/etcd" | ||
ETCD_DATA_DIR_BACKUP="/var/lib/etcd-backup" | ||
MANIFEST_STOPPED_DIR="${ASSET_DIR}/manifests-stopped" | ||
RESTORE_ETCD_POD_YAML="${CONFIG_FILE_DIR}/static-pod-resources/etcd-certs/configmaps/restore-etcd-pod/pod.yaml" | ||
ETCDCTL_BIN_DIR="${CONFIG_FILE_DIR}/static-pod-resources/bin" | ||
PATH=${PATH}:${ETCDCTL_BIN_DIR} | ||
|
||
# download etcdctl from upstream release assets | ||
function dl_etcdctl { | ||
local etcdimg=${ETCD_IMAGE} | ||
local etcdctr=$(podman create ${etcdimg}) | ||
local etcdmnt=$(podman mount "${etcdctr}") | ||
[ ! -d ${ETCDCTL_BIN_DIR} ] && mkdir -p ${ETCDCTL_BIN_DIR} | ||
cp ${etcdmnt}/bin/etcdctl ${ETCDCTL_BIN_DIR}/ | ||
umount "${etcdmnt}" | ||
podman rm "${etcdctr}" | ||
etcdctl version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o errtrace | ||
|
||
# example | ||
# ./etcd-snapshot-restore.sh $path-to-backup | ||
|
||
if [[ $EUID -ne 0 ]]; then | ||
echo "This script must be run as root" | ||
exit 1 | ||
fi | ||
|
||
source /etc/kubernetes/static-pod-resources/etcd-certs/configmaps/etcd-scripts/etcd.env | ||
source /etc/kubernetes/static-pod-resources/etcd-certs/configmaps/etcd-scripts/etcd-common-tools | ||
|
||
function usage { | ||
echo 'Path to the directory containing backup files is required: ./etcd-snapshot-restore.sh <path-to-backup>' | ||
echo 'The backup directory is expected to be contain two files:' | ||
echo ' 1. etcd snapshot' | ||
echo ' 2. A copy of the Static POD resources at the time of backup' | ||
exit 1 | ||
} | ||
|
||
# If the argument is not passed, or if it is not a directory, print usage and exit. | ||
if [ "$1" == "" ] || [ ! -d "$1" ]; then | ||
usage | ||
fi | ||
|
||
BACKUP_DIR="$1" | ||
BACKUP_FILE=$(ls -vd "${BACKUP_DIR}"/static_kuberesources*.tar.gz | tail -1) || true | ||
SNAPSHOT_FILE=$(ls -vd "${BACKUP_DIR}"/snapshot*.db | tail -1) || true | ||
|
||
if [ ! -f "${SNAPSHOT_FILE}" ]; then | ||
echo "etcd snapshot ${SNAPSHOT_FILE} does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Move manifests and stop static pods | ||
if [ ! -d "$MANIFEST_STOPPED_DIR" ]; then | ||
mkdir $MANIFEST_STOPPED_DIR | ||
fi | ||
|
||
# Move static pod manifests out of MANIFEST_DIR | ||
find ${MANIFEST_DIR} \ | ||
-maxdepth 1 \ | ||
-type f \ | ||
-printf '...stopping %P\n' \ | ||
-exec mv {} ${MANIFEST_STOPPED_DIR} \; | ||
|
||
# Wait for pods to stop | ||
sleep 30 | ||
|
||
# //TO DO: verify using crictl that etcd and other pods stopped. | ||
|
||
# Remove data dir | ||
echo "Moving etcd data-dir ${ETCD_DATA_DIR}/member to ${ETCD_DATA_DIR_BACKUP}" | ||
[ ! -d ${ETCD_DATA_DIR_BACKUP} ] && mkdir -p ${ETCD_DATA_DIR_BACKUP} | ||
mv ${ETCD_DATA_DIR}/member ${ETCD_DATA_DIR_BACKUP}/member | ||
|
||
# Copy snapshot to backupdir | ||
if [ ! -d ${ETCD_DATA_DIR_BACKUP} ]; then | ||
mkdir -p ${ETCD_DATA_DIR_BACKUP} | ||
fi | ||
cp -p ${SNAPSHOT_FILE} ${ETCD_DATA_DIR_BACKUP}/snapshot.db | ||
|
||
# Copy etcd restore pod yaml | ||
cp -p ${RESTORE_ETCD_POD_YAML} ${MANIFEST_DIR}/etcd-pod.yaml | ||
|
||
# Restore static pod resources | ||
tar -C ${CONFIG_FILE_DIR} -xzf ${BACKUP_FILE} static-pod-resources |
Oops, something went wrong.