官方文档

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. Scrapy爬虫框架(实战篇)【Scrapy框架对接Splash抓取javaScript动态渲染页面】

    (1).前言 动态页面:HTML文档中的部分是由客户端运行JS脚本生成的,即服务器生成部分HTML文档内容,其余的再由客户端生成 静态页面:整个HTML文档是在服务器端生成的,即服务器生成好了,再发送 ...

  2. 显著性检测(saliency detection)评价指标之KL散度距离Matlab代码实现

    步骤1:先定义KLdiv函数: function score = KLdiv(saliencyMap, fixationMap) % saliencyMap is the saliency map % ...

  3. C语言sprintf和sscanf函数用法

    以前刚用C语言的时候,觉得字符串很难处理,后来用多了,发现其实并非如此,C语言也提供了许多函数给程序员使用.今天记录一下两个常用的两个字符串处理函数:sprintf和sscanf 1. sprintf ...

  4. SSL,TLS

    今天突然收到邮件说SSL不能用了,基于SSL的HTTPS协议不通了,怎么办? java/android 的网络编程简直一窍不通,平时都是用到了问百度.只能恶补有关网络的知识了. 传输协议: 传输协议中 ...

  5. 基于tcp实现远程执行命令

    命令执行服务器: # Author : Kelvin # Date : 2019/1/30 20:10 from socket import * import subprocess ip_conf = ...

  6. 使用Rotativa在ASP.NET Core MVC中创建PDF

    在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP.NET MVC,那么Rot​​ativa工具已经可用,我们可以使用 ...

  7. 使用 Premiere 制作视频简介

    Premiere 简介 经常上B站或其他视频网站,有很多个人制作的有趣视频.也会想要自己制作视频.目前网上常见的视频剪辑软件有很多种,神剪辑.爱剪辑.会声会影.EDIUS等.但在专业视频剪辑师中,使用 ...

  8. javascript入门篇(三)

    字符串属性和方法 原始值字符串,如'liang', 没有属性和方法(因为他们不是对象). 原始值可以使用 JavaScript 的属性和方法,因为 JavaScript 在执行方法和属性时可以把原始值 ...

  9. 欢迎使用IdentityModel文档!- IdentityModel 中文文档(v1.0.0)

    IdentityModel是基于声明的身份,OAuth 2.0和OpenID Connect的.NET标准帮助程序库. 它具有以下高级功能: 标准OAuth 2.0和OpenID Connect端点的 ...

  10. Quartz.Net学习笔记

    一.概述 Quartz.NET是一个强大.开源.轻量的作业调度框架,是 OpenSymphony 的 Quartz API 的.NET移植,用C#改写,可用于winform和asp.net应用中.它灵 ...