欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
相关标签: 数据库&中间件