Last active
May 22, 2019 18:28
-
-
Save ironicbadger/48f9dfc4b3ad7f003bff84e7f66b508a to your computer and use it in GitHub Desktop.
OCP 3 etcd and master backups
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
#!/bin/bash | |
export ETCD_ENDPOINTS="https://ocp311-m1.ktz.lan:2379,https://ocp311-m2.ktz.lan:2379,https://ocp311-m3.ktz.lan:2379" | |
# master backup | |
mkdir git && cd git | |
git clone https://github.com/openshift/openshift-ansible-contrib.git | |
touch /etc/pki/ca-trust/source/anchors/test # github issue opened to avoid this step | |
./openshift-ansible-contrib/reference-architecture/day2ops/scripts/backup_master_node.sh | |
# check etcd health | |
ETCDCTL_API=3 etcdctl --cert="/etc/etcd/peer.crt" --key=/etc/etcd/peer.key --cacert="/etc/etcd/ca.crt" --endpoints ${ETCD_ENDPOINTS} endpoint health | |
ETCDCTL_API=3 etcdctl --cert="/etc/etcd/peer.crt" --key=/etc/etcd/peer.key --cacert="/etc/etcd/ca.crt" --endpoints ${ETCD_ENDPOINTS} member list | |
# etcd db backup | |
export ETCD_POD_MANIFEST="/etc/origin/node/pods/etcd.yaml" | |
# export ETCD_EP=$(grep https ${ETCD_POD_MANIFEST} | cut -d '/' -f3) | |
oc login -u system:admin | |
export ETCD_POD=$(oc get pods -n kube-system | grep -o '\S*etcd\S*' | grep -w ${HOSTNAME}) | |
oc exec ${ETCD_POD} -c etcd -- /bin/bash -c "ETCDCTL_API=3 etcdctl --cert /etc/etcd/peer.crt --key /etc/etcd/peer.key --cacert /etc/etcd/ca.crt --endpoints ${ETCD_ENDPOINTS} snapshot save /var/lib/etcd/snapshot.db" | |
# etcd config backup | |
mkdir -p /backup/$(hostname)/$(date +%Y%m%d)/etcd-config/ | |
cp -R /etc/etcd /backup/$(hostname)/$(date +%Y%m%d)/etcd-config/ | |
# get backed up data into a single tar archive, pay attention to | |
# the dirs included here (dates etc). by doing this after etcd dump | |
# etcd data is included | |
MYBACKUPDIR=/backup/$(hostname)/$(date +%Y%m%d) | |
mkdir -p /backup/$(hostname)/$(date +%Y%m%d)/etcd-db | |
cp /var/lib/etcd/snapshot.db /backup/$(hostname)/$(date +%Y%m%d)/etcd-db/ | |
tar -zcvf /backup/$(hostname)-$(date +%Y%m%d).tar.gz $MYBACKUPDIR | |
rm -rf /backup/$(hostname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment