Backup and Restore ETCD Database

  • Are this the correct commands to backup the ETCD DB:

ETCDCTL_API=3 etcdctl help

ETCDCTL_API=3 etcdctl --endpoints https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /tmp/snapshot-pre-boot.db

  • Are this the correct commands to Restore the ETCD DB:

ETCDCTL_API=3 etcdctl --endpoints=https://[127.0.0.1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt
–name=master
–cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key
–data-dir /var/lib/etcd-from-backup
–initial-cluster=master=https://127.0.0.1:2380
–initial-cluster-token=etcd-cluster-1
–initial-advertise-peer-urls=https://127.0.0.1:2380
snapshot restore /tmp/snapshot-pre-boot.db

  • Update ETCD manifest file with correct backup directory and token:

  • –data-dir=/var/lib/etcd-from-backup

  • –initial-cluster-token=etcd-cluster-1

  • Update ETCD manifest file with correct hostpath and volume:
    volumeMounts:

    • mountPath: /var/lib/etcd-from-backup
      name: etcd-data
    • mountPath: /etc/kubernetes/pki/etcd
      name: etcd-certs

    volumes:

    • hostPath:
      path: /var/lib/etcd-from-backup
      type: DirectoryOrCreate
      name: etcd-data
    • hostPath:
      path: /etc/kubernetes/pki/etcd
      type: DirectoryOrCreate

You can visit this post. ETCD - backup and restore management