etcd数据备份与恢复
etcd数据备份与恢复
单节点etcd数据备份与恢复
一、数据备份
1、设置环境变量
ETCDCTL_API=3
2、创建备份目录,使用快照备份
mkdir -p /data/etcd/backup
etcdctl snapshot save /data/etcd/backup/etcd.db
二、数据恢复
1、停止etcd服务
systemctl stop etcd
2、清理所有数据
rm -rf /data/etcd/data/*
3、执行恢复指令
etcdctl snapshot restore /data/etcd/backup/etcd.db \ --data-dir=/data/etcd/data \ --name etcd1 \ --initial-advertise-peer-urls=https://127.0.0.1:2380 \ --initial-cluster=etcd1=https://127.0.0.1:2380 \ --initial-cluster-token=etcd-1
4、启动etcd
systemctl start etcd
etcd集群数据备份与恢复
一、数据备份
1、设置环境变量
ETCDCTL_API=3
2、创建备份目录,使用快照备份
mkdir -p /data/etcd/backup
etcdctl --endpoints=https://192.168.110.12:2379 --cacert=/data/etcd/ssl/ca.pem --cert=/data/etcd/ssl/server.pem --key=/data/etcd/ssl/server-key.pem snapshot save /data/etcd/bakup/etcd.db
二、数据恢复
1、在所有节点创建好数据备份目录
mkdir -p /data/etcd/backup
2、复制快照到所有节点
scp /data/etcd/backup/etcd.db etcd2:/data/etcd/backup/etcd.db
scp /data/etcd/backup/etcd.db etcd3:/data/etcd/backup/etcd.db
3、关闭etcd集群所有节点etcd服务
systemctl stop etcd
4、在所有节点上分别执行恢复数据指令
ETCDCTL_API=3 etcdctl snapshot restore /data/etcd/backup/etcd.db \ --name etcd1 \ --initial-cluster etcd1=https://192.168.110.12:2380,etcd2=https://192.168.110.13:2380,etcd3=https://192.168.110.15:2380 \ --initial-cluster-token etcd-cluster-1 \ --initial-advertise-peer-urls https://192.168.110.12:2380 \ --data-dir=/data/etcd/data
根据节点信息修改红色部分数据。
5、启动etcd集群所有节点etcd服务
systemctl start etcd
6、查看集群状态
etcdctl --endpoints=https://192.168.110.12:2379,https://192.168.110.13:2379,https://192.168.110.15:2379 \ --cacert=/data/etcd/ssl/ca.pem \ --cert=/data/etcd/ssl/server.pem \ --key=/data/etcd/ssl/server-key.pem \ endpoint health