Etcdctl部署与备份脚本

#下载的命令放到/usr/local/bin
https://github.com/coreos/etcd/releases/download/v3.5.3/etcd-v3.5.3-linux-amd64.tar.gz
  • 设置别名
# vim /root/.bashrc
alias etcdctl='ETCDCTL_API=3  etcdctl --endpoints=127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key'
  • 执行环境变量
source /root/.bashrc 
  • 测试
etcdctl get / --keys-only --prefix
  • 备份脚本-证书可以省略我赖得改
[root@master0 share]# cat etcdbak.sh 
#!/bin/bash -v
#Etcd time scripts backup auther
DATE=`date +%Y-%m-%d_%H-%M-%S`
NODE_IPS="192.168.201.60"
CACERT="/etc/kubernetes/pki/etcd/ca.crt"
CERT="/etc/kubernetes/pki/etcd/server.crt"
KEY="/etc/kubernetes/pki/etcd/server.key"
BACKUP_DIR="/data/backups/etcd-bak"
ETCDCTL_API=3 /usr/bin/etcdctl snapshot save ${BACKUP_DIR}/etcd-snapshot-${DATE}.db \
  --cacert=${CACERT} \
  --cert=${CERT} \
  --key=${KEY} \
  --endpoints="${NODE_IPS}:2379"
 
find $BACKUP_DIR/ -type f -mtime +20 -exec rm -f {} \;
posted @ 2023-03-12 09:17  YIDADA-SRE  阅读(83)  评论(0编辑  收藏  举报