code/etcd-inmemory/files/opt/wamblee/etcd/bin/etcd-backup

34 lines
815 B
Plaintext
Raw Normal View History

2023-02-26 12:36:15 +00:00
#!/bin/bash
PATH=/opt/wamblee/etcd/bin:$PATH
if [[ $# -ne 1 ]]
then
echo "Usage: $0 <backupname>" 1>&2
exit 1
fi
BACKUP="$1"
IMAGE="$( /opt/wamblee/etcd/bin/docker ps | awk '/\/etcd$/ { print $2}' )"
if [[ -z "$IMAGE" ]]
then
echo "$0: could not create backup" 1>&2
exit 1
fi
docker run --network host \
-v /etc/kubernetes/pki/etcd:/etc/kubernetes/pki/etcd \
-v /var/lib/wamblee/etcd:/var/lib/wamblee/etcd \
--rm "$IMAGE" sh -c "etcdctl \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt \
--key=/etc/kubernetes/pki/etcd/healthcheck-client.key \
snapshot save /var/lib/wamblee/etcd/$BACKUP"
echo "IMAGE=$IMAGE" > /var/lib/wamblee/etcd/etcdimage
echo "Backup done at /var/lib/wamblee/etcd/$BACKUP"