etcd3集群数据备份与恢复
ETCD3数据备份与恢复
1.备份数据
备份etcd集群任意一个节点的数据就行
export ETCD_ENDPOINTS="https://192.168.0.20:2379,https://192.168.0.21:2379,https://192.168.0.22:2379" etcdctl --endpoints=${ETCD_ENDPOINTS} snapshot save "/home/snapshot.db"
2.恢复数据
将/home/snapshot.db拷贝到其他etcd集群节点同一目录,之后在各个节点分别执行以下命令,--data-dir是新的数据目录,原数据目录是/data/apps/etcd/data/default.etcd,各个参数配置可查看原配置文件/data/apps/etcd/etc/etcd.conf
节点192.168.0.20执行
export ETCDCTL_API=3 etcdctl snapshot restore /home/snapshot.db \ --data-dir="/data/apps/etcd/data/etcd.restore" \ --name etcd-01 \ --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls "https://192.168.0.20:2380"
节点192.168.0.21执行
export ETCDCTL_API=3 etcdctl snapshot restore /home/snapshot.db \ --data-dir="/data/apps/etcd/data/etcd.restore" \ --name etcd-02 \ --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls "https://192.168.0.21:2380"
节点192.168.0.22执行
export ETCDCTL_API=3 etcdctl snapshot restore /home/snapshot.db \ --data-dir="/data/apps/etcd/data/etcd.restore" \ --name etcd-03 \ --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls "https://192.168.0.22:2380"
3.停止各个节点的etcd服务
systemctl stop etcd
4.使用新的数据目录启动各个节点etcd
需要修改/data/apps/etcd/etc/etcd.conf配置文件中--data-dir对应的新的数据目录为/data/apps/etcd/data/etcd.restore
#[Member] ETCD_NAME="etcd-01" #ETCD_DATA_DIR="/data/apps/etcd/data/default.etcd" ETCD_DATA_DIR="/data/apps/etcd/data/etcd.restore" ETCD_LISTEN_PEER_URLS="https://192.168.0.20:2380" ETCD_LISTEN_CLIENT_URLS="https://127.0.0.1:2379,https://192.168.0.20:2379" # #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.20:2380" ETCD_ADVERTISE_CLIENT_URLS="https://127.0.0.1:2379,https://192.168.0.20:2379" ETCD_INITIAL_CLUSTER="etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" #[Security] ETCD_CERT_FILE="/data/apps/etcd/ssl/etcd.pem" ETCD_KEY_FILE="/data/apps/etcd/ssl/etcd-key.pem" ETCD_TRUSTED_CA_FILE="/data/apps/etcd/ssl/etcd-ca.pem" ETCD_PEER_CERT_FILE="/data/apps/etcd/ssl/etcd.pem" ETCD_PEER_KEY_FILE="/data/apps/etcd/ssl/etcd-key.pem" ETCD_PEER_TRUSTED_CA_FILE="/data/apps/etcd/ssl/etcd-ca.pem" # [Logging] ETCD_DEBUG="false" ETCD_LOG_OUTPUT="default"
之后启动etcd即可
systemctl start etcd