1. 程式人生 > >etcd數據庫備份與還原

etcd數據庫備份與還原

恢復 1.3 1.2 host roo efault res -h .tar.gz

1. 備份etcd

1.1 手動備份數據

etcdctl backup --data-dir /var/lib/etcd/default.etcd --backup-dir 備份目錄

1.2 腳本備份數據

使用etcd自帶命令etcdctl進行etc備份,腳本如下:

#!/bin/bash
date_time=`date +%Y%m%d`
etcdctl backup --data-dir /var/lib/etcd/default.etcd --backup-dir /root/etcd71-${date_time}.etcd
tar cvzf etcd71-${date_time}.tar.gz etcd71-${date_time}.etcd

1.3 刪除7天前歷史備份

find /root/*.etcd -ctime +7 -exec rm -r {} \;
find /root/*.gz -ctime +7 -exec rm -r {} \;

2. 恢復etcd

2.1 單機運行

etcd --data-dir=/var/lib/etcd/default.etcd --force-new-cluster &

2.2 查看id

etcdctl member list
1c4358be138c6d94: name=default peerURLs=https://192.168.61.71:2380 clientURLs=http://localhost:2379 isLeader=true

2.3 數據同步

curl http://127.0.0.1:2379/v2/members/1c4358be138c6d94 -XPUT -H "Content-Type:application/json" -d ‘{"peerURLs":["http://127.0.0.1:2379"]}‘

2.4 結束單機運行

pkill -9 etcd

2.5 重新啟動服務

systemctl restart etcd
systemctl status etcd

etcd數據庫備份與還原