etcd 备份与恢复
程序员文章站
2022-07-13 22:37:39
...
- etcd备份脚本
#!/bin/bash
#
ETCDCTL_PATH='/opt/kube/bin/etcdctl'
BACKUP_DIR='/etcd_backup'
DATE=`date +%Y%m%d-%H%M%S`
[ ! -d $BACKUP_DIR ] && mkdir -p $BACKUP_DIR
export ETCDCTL_API=3;$ETCDCTL_PATH snapshot save $BACKUP_DIR/snapshot-$DATE\.db
#只留10份
cd $BACKUP_DIR;ls -lt $BACKUP_DIR|awk '{if(NR>11){print "rm -rf "$9}}'|sh
- etcd恢复脚本
恢复参数请查看/etc/systemd/system/etcd.service
systemctl stop etcd
mv /var/lib/etcd /var/lib/etcd.bak
etcdctl snapshot restore snapshot.db \
--name etcd1 \
--initial-cluster etcd1=https://192.168.11.193:2380 \
--initial-advertise-peer-urls https://192.168.11.193:2380 \
--data-dir /var/lib/etcd
systemctl start etcd