ETCD备份脚本

#!/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值