官方文档

https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/recovery.md

一、运行3个etcd节点

我们用一台机器的不同商品来模拟3个etcd节点

启动脚本差不多,这里我写成了一个shell如下,vim /home/chenqionghe/etcdTest/run-node.sh

#!/usr/bin/env bash

usage() {
echo "Usage: `basename $0` nodeName dataDir clientPort peerPort cluster "
echo "例如:`basename $0` node1 /data/node1.etcd 11379 11380 \"node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380\""
exit 1;
}
# 检测参数
if [ $# -lt 5 ];then
usage
exit 1
fi name=$1
dataDir=$2
clientPort=$3
peerPort=$4
cluster=$5
token="light-weight-baby" # 运行节点
etcd --name ${name} \
--data-dir ${dataDir} \
--initial-cluster-token ${token} \
--initial-advertise-peer-urls http://127.0.0.1:${peerPort} \
--listen-peer-urls http://0.0.0.0:${peerPort} \
--listen-client-urls http://0.0.0.0:${clientPort} \
--advertise-client-urls http://0.0.0.0:${clientPort} \
--initial-cluster ${cluster} \
--initial-cluster-state new

使用方式如下

Usage: run-node.sh nodeName dataDir clientPort peerPort cluster

接下来我们启动3个节点

export cluster="node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380"
./run-node.sh node1 /home/chenqionghe/etcdTest/node1.etcd 11379 11380 ${cluster}
./run-node.sh node2 /home/chenqionghe/etcdTest/node2.etcd 12379 12380 ${cluster}
./run-node.sh node3 /home/chenqionghe/etcdTest/node3.etcd 13379 13380 ${cluster}

ok,我们看到3个节点都已经起来了

二、准备数据

这里我们设置几个数据项

export ETCD_ENDPOINTS="http://127.0.0.1:11379,http://127.0.0.1:12379,http://127.0.0.1:13379"
# 设置数据
etcdctl --endpoints=${ETCD_ENDPOINTS} put /cqh chenqionghe
etcdctl --endpoints=${ETCD_ENDPOINTS} put /cqh/bench_press 100kg
etcdctl --endpoints=${ETCD_ENDPOINTS} put /cqh/dead_lift 160kg
etcdctl --endpoints=${ETCD_ENDPOINTS} put /cqh/deep_squal 140kg

测试集群和设置的数据

root@ubuntu:/home/chenqionghe/test/etcd# etcdctl --endpoints=${ETCD_ENDPOINTS} member list
25ad84e18438ca4e, started, node2, http://127.0.0.1:12380, http://0.0.0.0:12379
3d78c9dc937b8bce, started, node3, http://127.0.0.1:13380, http://0.0.0.0:13379
9328257f7d3eded0, started, node1, http://127.0.0.1:11380, http://0.0.0.0:11379
root@ubuntu:/home/chenqionghe/test/etcd# etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --keys-only
/cqh
/cqh/bench_press
/cqh/dead_lift
/cqh/deep_squal
root@ubuntu:/home/chenqionghe/test/etcd# etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --print-value-only
chenqionghe
100kg
160kg
140kg

都已经生效

三、备份数据

很简单,就是设置一个保存的文件

export ETCD_ENDPOINTS="http://127.0.0.1:11379,http://127.0.0.1:12379,http://127.0.0.1:13379"
etcdctl --endpoints=${ETCD_ENDPOINTS} snapshot save "/home/chenqionghe/etcdTest/backup/snapshot.db"

四、恢复数据

执行恢复,我们指定恢复的目录为nodeName.etcd.restore,比之前的数据目录多了个.restore

export ETCDCTL_API=3
etcdctl snapshot restore /home/chenqionghe/etcdTest/backup/snapshot.db \
--data-dir="/home/chenqionghe/etcdTest/node1.etcd.restore" \
--name node1 \
--initial-cluster "node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380" \
--initial-cluster-token etcdv3-cluster \
--initial-advertise-peer-urls http://127.0.0.1:11380 export ETCDCTL_API=3
etcdctl snapshot restore /home/chenqionghe/etcdTest/backup/snapshot.db \
--data-dir="/home/chenqionghe/etcdTest/node2.etcd.restore" \
--name node2 \
--initial-cluster "node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380" \
--initial-cluster-token etcdv3-cluster \
--initial-advertise-peer-urls http://127.0.0.1:12380 export ETCDCTL_API=3
etcdctl snapshot restore /home/chenqionghe/etcdTest/backup/snapshot.db \
--data-dir="/home/chenqionghe/etcdTest/node3.etcd.restore" \
--name node3 \
--initial-cluster "node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380" \
--initial-cluster-token etcdv3-cluster \
--initial-advertise-peer-urls http://127.0.0.1:13380

测试恢复,我们先删除所有示例数据

etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh chenqionghe
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/bench_press 100kg
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/dead_lift 160kg
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/deep_squal 140kg

确认已经没有数据了

# 测试恢复,先删除所有示例数据
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh chenqionghe
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/bench_press 100kg
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/dead_lift 160kg
etcdctl --endpoints=${ETCD_ENDPOINTS} del /cqh/deep_squal 140kg # 确认已经没有数据了
etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --keys-only
etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --print-value-only

停止之前的3个节点,再重新根据.restore目录分别运行3个节点

export cluster="node1=http://127.0.0.1:11380,node2=http://127.0.0.1:12380,node3=http://127.0.0.1:13380"
./run-node.sh node1 /home/chenqionghe/etcdTest/node1.etcd.restore 11379 11380 ${cluster}
./run-node.sh node2 /home/chenqionghe/etcdTest/node2.etcd.restore 12379 12380 ${cluster}
./run-node.sh node3 /home/chenqionghe/etcdTest/node3.etcd.restore 13379 13380 ${cluster}

重新执行命令

root@ubuntu:/home/chenqionghe/test/etcd# etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --keys-only
/cqh /cqh/bench_press /cqh/dead_lift /cqh/deep_squal root@ubuntu:/home/chenqionghe/test/etcd# etcdctl --endpoints=${ETCD_ENDPOINTS} get /cqh --prefix --print-value-only
chenqionghe
100kg
160kg
140kg

看到数据恢复了,ok,就这么简单

etcd v3集群备份和恢复的更多相关文章

  1. [How to]HBase集群备份方法--Replication机制

    1.简介 HBase备份的方法在[How to]HBase集群备份方法文章中已经有些介绍,但是这些方法都不是HBase本身的特性在支持,都是通过MR计算框架结合HBase客户端的方式,或者直接拷贝HB ...

  2. [How to]HBase集群备份方法

    1.简介 当HBase数据库中存在非常重要的业务数据的时候为了保护数据的可以对数据进行备份处理.对于HBase来说从备份操作来看可分为离线备份和在线备份. 2. 前准备 在测试环境上准备有哦两套HBa ...

  3. k8s集群部署之环境介绍与etcd数据库集群部署

    角色 IP 组件 配置 master-1 192.168.10.11 kube-apiserver kube-controller-manager kube-scheduler etcd 2c 2g ...

  4. kingbaseES V8R6集群备份恢复案例之---备库作为repo主机执行物理备份

    ​ 案例说明: 此案例是在KingbaseES V8R6集群环境下,当主库磁盘空间不足时,执行sys_rman备份,将集群的备库节点作为repo主机,执行备份,并将备份存储在备库的磁盘空间. 集群架构 ...

  5. etcd创建集群并增加节点

    下载安装 从这下载https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz tar ...

  6. kubernetes-集群备份和恢复

    一.备份   思路: ①集群运行中etcd数据备份到磁盘上 ②kubeasz项目创建的集群,需要备份CA证书文件,以及ansible的hosts文件   [deploy节点操作] 1:创建存放备份文件 ...

  7. etcd+calico集群的部署

    etcd单机模式 设置环境变量 1 export HostIP="192.168.12.50" 执行如下命令,打开etcd的客户端连接端口4001和2379.etcd互联端口238 ...

  8. etcd单机集群

    etcd在单机部署集群,可以先弄清楚配置文件参数的意思.起3个集成监听不同的端口号 1. 启动 在/etc/soft/etcd/node1文件夹中,创建脚本start1.sh etcd --name ...

  9. k8s部署etcd数据库集群

    ⒈下载 https://github.com/etcd-io/etcd/releases ⒉解压 tar -zxvf etcd-v3.3.12-linux-amd64.tar.gz ⒊移动可执行文件及 ...

随机推荐

  1. BZOJ_4892_[Tjoi2017]dna_哈希

    BZOJ_4892_[Tjoi2017]dna_哈希 Description 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的 性状,但是研究人员 ...

  2. BZOJ_3427_Poi2013 Bytecomputer_DP

    BZOJ_3427_Poi2013 Bytecomputer_DP Description 给定一个{-1,0,1}组成的序列,你可以进行x[i]=x[i]+x[i-1]这样的操作,求最少操作次数使其 ...

  3. iOS 远程推送通知 详解

    1: ios本地通知和远程通知 http://wangjun.easymorse.com/?p=1482 2: 苹果远程通知服务申请激活例图 (外国佬写的.) http://mobiforge.com ...

  4. laravel rbac的用户 角色 权限的crud

    user.php <?php /* |-------------------------------------------------------------------------- | W ...

  5. MySQL(七)DQL之分组查询

    一.语法 select 分组函数,分组后的字段from 表[where 筛选条件]group by 分组的字段[having 分组后的筛选][order by 排序列表] 二.特点 分组前筛选:whe ...

  6. 从壹开始前后端分离【 .NETCore2.1 +Vue 2 +AOP+DI】框架之一 || 前言

    缘起 作为一个.Net攻城狮已经4年有余了,一直不温不火,正好近来项目不是很忙,闲得无聊,搞一搞新技术,一方面是打发无聊的时间,一方面也是督促自己该学习辣!身边的大神都转行的转行,加薪的加薪,本人比较 ...

  7. FreeSql 扩展包实现 Dapper 的使用习惯

    简介 FreeSql.Connection.Extensions 这是 FreeSql 衍生出来的扩展包,实现(Mysql/postgresql/sqlserver/Oracle/SQLite)数据库 ...

  8. 深度召回模型在QQ看点推荐中的应用实践

    本文由云+社区发表 作者:腾讯技术工程 导语:最近几年来,深度学习在推荐系统领域中取得了不少成果,相比传统的推荐方法,深度学习有着自己独到的优势.我们团队在QQ看点的图文推荐中也尝试了一些深度学习方法 ...

  9. Java并发编程面试题 Top 50 整理版

    本文在 Java线程面试题 Top 50的基础上,对部分答案进行进行了整理和补充,问题答案主要来自<Java编程思想(第四版)>,<Java并发编程实战>和一些优秀的博客,当然 ...

  10. Java 在PDF 中添加超链接

    对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...