#!/bin/bash
ETCD_SERVERS_ADDR='https://10.X.X.1:2379,https://10.X.X.2:2379,https://10.X.X.3:2379'
ETCD_CA='/etc/kubernetes/ssl/ca.pem'
ETCD_CERT='/etc/kubernetes/ssl/etcd.pem'
ETCD_KEY='/etc/kubernetes/ssl/etcd-key.pem'
BACKUP_DATA_PATH='/data2/etcd-backup/bkdata'
DATETAG=$(date +%Y%m%d)
function MemberList(){
# 查看etcd所有节点(多个节点的话endpoints要加上,下同)
ETCDCTL_API=3 /opt/kube/bin/etcdctl --endpoints=${ETCD_SERVERS_ADDR} \
--cacert=${ETCD_CA} \
--cert=${ETCD_CERT} \
--key=${ETCD_KEY} member list
}
function EpStatus(){
# 查看节点信息
ETCDCTL_API=3 /opt/kube/bin/etcdctl --endpoints=${ETCD_SERVERS_ADDR} \
--cacert=${ETCD_CA} \
--cert=${ETCD_CERT} \
--key=${ETCD_KEY} endpoint status --write-out=table
}
function EpHealth(){
# 查看etcd节点健康状况
ETCDCTL_API=3 /opt/kube/bin/etcdctl --endpoints=${ETCD_SERVERS_ADDR} \
--cacert=${ETCD_CA} \
--cert=${ETCD_CERT} \
--key=${ETCD_KEY} endpoint health
}
function BackupSave(){
# 备份数据,使用一个节点即可
SERVERIP="$(echo ${ETCD_SERVERS_ADDR}|awk -F ',' '{print $1}')"
ETCDCTL_API=3 /opt/kube/bin/etcdctl --endpoints=${SERVERIP} \
--cacert=${ETCD_CA} \
--cert=${ETCD_CERT} \
--key=${ETCD_KEY} snapshot save ${BACKUP_DATA_PATH}/etcd-snapshot-${DATETAG}.db
}
function main(){
echo " ------------ $(date) 开始 ---------- " >> ${BACKUP_DATA_PATH}/zx.log
if [ -f ${BACKUP_DATA_PATH}/etcd-snapshot-${DATETAG}.db ];then
echo -e "备份文件已存在,不再进行备份\n" >> ${BACKUP_DATA_PATH}/zx.log
exit 0
else
BackupSave
fi
if [ `echo $?` -eq 0 ];then
echo -e "备份成功!\n" >> ${BACKUP_DATA_PATH}/zx.log
else
echo -e "备份有问题!\n" >> ${BACKUP_DATA_PATH}/zx.log
fi
}
main
ETCD备份脚本
最新推荐文章于 2024-09-20 11:19:49 发布