• etcd单节点数据备份与恢复


    插入测试数据

    # etcdctl put  smith  7369
    # etcdctl put  allen  7499
    # etcdctl put  ward   7521
    # etcdctl put  jones  7566
    # etcdctl put  martin 7654
    # etcdctl put  blake  7698
    # etcdctl put  clark  7782
    # etcdctl put  scott  7788
    # etcdctl put  king   7839
    # etcdctl put  turner 7844
    # etcdctl put  adams  7876
    # etcdctl put  james  7900
    # etcdctl put  ford   7902
    # etcdctl put  miller 7934

    查看数据

    # etcdctl get --prefix ""
    adams
    7876
    allen
    7499
    blake
    7698
    clark
    7782
    ford
    7902
    james
    7900
    jones
    7566
    king
    7839
    martin
    7654
    miller
    7934
    scott
    7788
    smith
    7369
    turner
    7844
    ward
    7521

    做快照

    # etcdctl snapshot save backup.db
    {"level":"info","ts":1570085496.5022638,"caller":"snapshot/v3_snapshot.go:109","msg":"created temporary db file","path":"backup.db.part"}
    {"level":"warn","ts":"2019-10-03T14:51:36.503+0800","caller":"clientv3/retry_interceptor.go:116","msg":"retry stream intercept"}
    {"level":"info","ts":1570085496.5036564,"caller":"snapshot/v3_snapshot.go:120","msg":"fetching snapshot","endpoint":"127.0.0.1:2379"}
    {"level":"info","ts":1570085496.5214782,"caller":"snapshot/v3_snapshot.go:133","msg":"fetched snapshot","endpoint":"127.0.0.1:2379","took":0.018938519}
    {"level":"info","ts":1570085496.521635,"caller":"snapshot/v3_snapshot.go:142","msg":"saved","path":"backup.db"}
    Snapshot saved at backup.db

    查看快照信息

    # etcdctl snapshot status backup.db --write-out=table
    +----------+----------+------------+------------+
    |   HASH   | REVISION | TOTAL KEYS | TOTAL SIZE |
    +----------+----------+------------+------------+
    | 6d1803a9 |      110 |        146 |      37 kB |
    +----------+----------+------------+------------+

    清空数据

    # etcdctl del --prefix ""
    14

    删除当前etcd的data目录,否则会报错目录已存在

    # rm -rf /usr/local/etcd/data

    恢复数据

    # etcdctl snapshot restore backup.db --data-dir="/usr/local/etcd/data"
    {"level":"info","ts":1570085656.639806,"caller":"snapshot/v3_snapshot.go:286","msg":"restoring snapshot","path":"backup.db","wal-dir":"/usr/local/etcd/data/member/wal","data-dir":"/usr/local/etcd/data","snap-dir":"/usr/local/etcd/data/member/snap"}
    {"level":"info","ts":1570085656.7266932,"caller":"membership/cluster.go:392","msg":"added member","cluster-id":"cdf818194e3a8c32","local-member-id":"0","added-peer-id":"8e9e05c52164694d","added-peer-peer-urls":["http://localhost:2380"]}
    {"level":"info","ts":1570085656.7834268,"caller":"snapshot/v3_snapshot.go:299","msg":"restored snapshot","path":"backup.db","wal-dir":"/usr/local/etcd/data/member/wal","data-dir":"/usr/local/etcd/data","snap-dir":"/usr/local/etcd/data/member/snap"}

    恢复完成后需要将从备份重新生成的data目录的属主和属组修改为etcd系统服务中的对应属主和属组

    # chown -R tnuser.dba /usr/local/etcd/data

    重启etcd系统服务

    # systemctl stop etcd
    # systemctl start etcd

    再次查看恢复的数据

    # etcdctl get --prefix ""
    adams
    7876
    allen
    7499
    blake
    7698
    clark
    7782
    ford
    7902
    james
    7900
    jones
    7566
    king
    7839
    martin
    7654
    miller
    7934
    scott
    7788
    smith
    7369
    turner
    7844
    ward
    7521
  • 相关阅读:
    人才培养的金字塔模型
    3D建模技术-讲稿-5-基础
    3D建模技术-讲稿-4-基础
    3D建模技术-讲稿-3-基础
    3D建模技术-讲稿-1-入门
    3D建模技术-讲稿-2-基础
    3D建模技术-讲稿-1-方凳
    the latest Ext2Fsd(ext2fsd-0.69) doesn't work after windows 10 --- solved using ext2fsd-0.53 or 0.68
    欢迎同学们参加新乡学院2019年3D打印暑期夏令营
    (OK) 自己动手构建Linux发行版---简版
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11619795.html
Copyright © 2020-2023  润新知