From f40e9b504876a0121d3a26fc48472cb2f7becf8d Mon Sep 17 00:00:00 2001 From: Mike Lambert Date: Thu, 19 Oct 2017 12:27:53 -0500 Subject: [PATCH] NDS-886: Replace etcddumper in backup.sh with something that actually works (#2) * NDS-886: Replace etcddumper in backup.sh with something that actually works * Making sure everything is committed up here * Added then to resolve bash error * Added then to resolve bash error * Added then to resolve bash error * I didn't mean to commit that change... whoops * Update list-backups.sh * Update retrieve-backup.sh --- Dockerfile | 25 +++++++++++++++++-------- README.md | 2 +- scripts/backup.sh | 19 ++++++++++++------- scripts/list-backups.sh | 11 ++++++++--- scripts/retrieve-backup.sh | 11 ++++++++--- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02de66b..7f235a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,29 @@ FROM debian:jessie # -# Install wget/ssh/cron/vim/pip via apt, and etcdumper via pip +# Install wget/ssh/cron/vim/nodejs/npm via apt # RUN apt-get -qq update && \ apt-get -qq install --no-install-recommends \ - wget \ - vim \ - cron \ - openssh-client \ - python-pip && \ - pip install etcddump && \ + wget \ + vim \ + curl \ + sudo \ + cron \ + openssh-client \ + git \ + npm && \ + curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - && \ + apt-get -qq update && \ + apt-get -qq install nodejs && \ + ln -s /usr/local/bin/node /usr/local/bin/nodejs && \ apt-get -qq autoremove && \ apt-get -qq autoclean && \ apt-get -qq clean all && \ - rm -rf /var/cache/apk/* /go + rm -rf /var/cache/apk/* /tmp/* /var/lib/apt/lists/* + +# Install etcd-load +RUN npm install -g etcd-load # # Download kubectl binary diff --git a/README.md b/README.md index 40bfbce..893d980 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ WARNING: `C /` will extract over the existing glfs data # Restore ETCD from backup ```bash -etcdumper --file=17-04-29.2228/17-04-29.2228-etcd-backup.json restore ${ETCD_HOST}:${ETCD_PORT} +etcd-load restore --etc=${ETCD_HOST}:${ETCD_PORT} 17-04-29.2228/17-04-29.2228-etcd-backup.json ``` NOTE: This is currently broken... we are investigating replacements for the `etcdumper` tool. diff --git a/scripts/backup.sh b/scripts/backup.sh index 5fb026d..c970111 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,15 +1,20 @@ #!/bin/bash [ $DEBUG ] && set -x +if [ "${CLUSTER_ID}" == "" ]; +then + echo "You must specify a CLUSTER_ID" + exit 1; +fi + # XXX: Set this to "echo" to for a dry-run DEBUG="" # Grab date / cluster name DATE=$(date +%y-%m-%d.%H%M) -IFS='-' read -ra HOST <<< "${HOSTNAME:-localhost}" -TARGET_PATH="${BACKUP_DEST:-/ndsbackup}/${HOST[0]}/${DATE}" +TARGET_PATH="${BACKUP_DEST:-/ndsbackup}/${CLUSTER_ID}/${DATE}" -echo "Backup started: ${DATE}" +echo "Backup started for ${CLUSTER_ID}: ${DATE} -> ${TARGET_PATH}" # Use the above to build our base commands SSH_ARGS="-i ${BACKUP_KEY:-backup.pem} -o StrictHostKeyChecking=no " @@ -22,15 +27,15 @@ $DEBUG ssh ${SSH_ARGS} ${SSH_TARGET} "mkdir -p ${TARGET_PATH}" $DEBUG tar czf - ${BACKUP_SRC} | $DEBUG ssh ${SSH_ARGS} ${SSH_TARGET} "cat - > ${TARGET_PATH}/${DATE}.glfs-state.tgz" # Dump etcd state -$DEBUG /usr/local/bin/etcdumper dump http://${ETCD_HOST:-localhost}:${ETCD_PORT:-2379} --file /tmp/${DATE}-etcd-backup.json +$DEBUG etcd-load dump --etcd=http://${ETCD_HOST:-localhost}:${ETCD_PORT:-2379} /tmp/${DATE}-etcd-backup.json $DEBUG scp ${SSH_ARGS} /tmp/${DATE}-etcd-backup.json ${SSH_TARGET}:${TARGET_PATH}/${DATE}-etcd-backup.json -# Dump Kubernetes cluster state +# Dump Kubernetes cluster state? # TODO: Verify kubeconfig is correct / present # FIXME: kubectl cluster-info dump is currently incomplete, as it relies on the broken kubectl logs # FIXME: See https://github.com/kubernetes/kubernetes/issues/38774 -$DEBUG /usr/local/bin/kubectl cluster-info dump | $DEBUG ssh ${SSH_ARGS} ${SSH_TARGET} sudo "cat - > ${TARGET_PATH}/${DATE}-kubectl.dump" +#$DEBUG /usr/local/bin/kubectl cluster-info dump | $DEBUG ssh ${SSH_ARGS} ${SSH_TARGET} sudo "cat - > ${TARGET_PATH}/${DATE}-kubectl.dump" -echo "Backup complete: ${DATE}" +echo "Backup complete for ${CLUSTER_ID}: ${DATE}" # TODO: Delete local backups after successful transfer? diff --git a/scripts/list-backups.sh b/scripts/list-backups.sh index 19e7438..74e96e4 100755 --- a/scripts/list-backups.sh +++ b/scripts/list-backups.sh @@ -1,15 +1,20 @@ #!/bin/bash [ $DEBUG ] && set -x +if [ "${CLUSTER_ID}" == "" ]; +then + echo "You must specify a CLUSTER_ID for the backup process" + exit 1; +fi + # XXX: Set this to "echo" to for a dry-run DEBUG="" # Grab date / cluster name DATE=$(date +%y-%m-%d.%H%M) -IFS='-' read -ra HOST <<< "${HOSTNAME:-localhost}" -TARGET_PATH=${BACKUP_DEST:-/ndsbackup}/${HOST[0]} +TARGET_PATH=${BACKUP_DEST:-/ndsbackup}/${CLUSTER_ID} -echo "Listing known backups for ${HOST[0]}:" +echo "Listing known backups for ${CLUSTER_ID}:" # Use the above to build our base commands SSH_ARGS="-i ${BACKUP_KEY:-backup.pem} -o StrictHostKeyChecking=no " diff --git a/scripts/retrieve-backup.sh b/scripts/retrieve-backup.sh index e7c0e90..d3c8503 100755 --- a/scripts/retrieve-backup.sh +++ b/scripts/retrieve-backup.sh @@ -1,14 +1,19 @@ #!/bin/bash [ $DEBUG ] && set -x +if [ "${CLUSTER_ID}" == "" ]; +then + echo "You must specify a CLUSTER_ID for the backup process" + exit 1; +fi + # XXX: Set this to "echo" to for a dry-run DEBUG="" # Grab date / cluster name -IFS='-' read -ra HOST <<< "${HOSTNAME:-localhost}" -TARGET_PATH=${BACKUP_DEST:-/ndsbackup}/${HOST[0]}/$1 +TARGET_PATH=${BACKUP_DEST:-/ndsbackup}/${CLUSTER_ID}/$1 -echo "Retrieving backup $1 for ${HOST[0]}: ${DATE}" +echo "Retrieving backup $1 for ${CLUSTER_ID}: ${DATE}" # Use the above to build our base commands SSH_ARGS="-i ${BACKUP_KEY:-backup.pem} -o StrictHostKeyChecking=no "