备份
通常而言,etcd都是集群部署,其实并不需要额外备份,但实在是架不住猪队友误操作。
写一个简单的etcd备份脚本如下:
#!/bin/bash
set -e
exec >> /var/log/backup_etcd.log
Date=`date +%Y-%m-%d-%H-%M`
EtcdEndpoints="localhost:2379"
EtcdCmd="/usr/bin/etcdctl"
BackupDir="/home/www/server/backup/etcd"
BackupFile="snapshot.db.$Date"
echo "`date` backup etcd..."
export ETCDCTL_API=3
$EtcdCmd --endpoints $EtcdEndpoints snapshot save $BackupDir/$BackupFile
echo "`date` backup done!"
恢复
etcdctl snapshot restore snapshot.db.2019-05-21-10-02 -data-dir /home/www/server/etcd
参数说明:
- restore: 指定用于恢复的快照文件
- -data-dir:恢复到哪个目录