Skip to content

Commit

Permalink
NDS-886: Replace etcddumper in backup.sh with something that actually…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
bodom0015 authored and craig-willis committed Oct 19, 2017
1 parent 2d9894c commit f40e9b5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
25 changes: 17 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 12 additions & 7 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -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 "
Expand All @@ -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?
11 changes: 8 additions & 3 deletions scripts/list-backups.sh
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down
11 changes: 8 additions & 3 deletions scripts/retrieve-backup.sh
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down

0 comments on commit f40e9b5

Please sign in to comment.