话不多说,直接上脚本,实际应用时只要修改对应的node列表值即可。
#! /bin/bash
ETCDCTL_PATH='/usr/local/bin/etcdctl'
ETCD_DATA_DIR="/var/lib/etcd"
BACKUP_DIR="/data/backups/kube_etcd/etcd-$(date +%Y-%m-%d_%H:%M:%S)"
ETCDCTL_CERT="/etc/kubernetes/ssl/etcd/etcd.pem"
ETCDCTL_KEY="/etc/kubernetes/ssl/etcd/etcd-key.pem"
ETCDCTL_CA_FILE="/etc/kubernetes/ssl/ca.pem"
[ ! -d $BACKUP_DIR ] && mkdir -p $BACKUP_DIR
sleep 3
for node in 192.168.0.146 192.168.0.147 192.168.0.148;do
echo "Backing up $node..."
export ETCDCTL_API=3;$ETCDCTL_PATH --endpoints="https://$node:2379" snapshot save $BACKUP_DIR/snapshot-$node.db \
--cacert="$ETCDCTL_CA_FILE" \
--cert="$ETCDCTL_CERT" \
--key="$ETCDCTL_KEY"
done
sleep 3
cd $BACKUP_DIR/../;ls -lt |awk '{if(NR>10){print "rm -rf "$9}}'|sh
tar czf $BACKUP_DIR.tar.gz $BACKUP_DIR
#添加计划任务
* */2 * * * /bin/bash /data/etcd_back.sh
本文由 Mr Gu 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Feb 19, 2024 at 10:39 am