启动仓库
docker-compose文件中添加:
环境变量
path.repo=/data/backup
目录挂载
/data/info-push-server/data/elasticsearch/backup:/data/backup
environment:
- discovery.type=single-node
# 禁用https
- xpack.security.enabled=false
# 限制内存
- ES_JAVA_OPTS=-Xms64m -Xmx1024m
# 备份路径
- path.repo=/data/backup
ports:
- "9200:9200"
volumes:
- /data/info-push-server/data/elasticsearch/backup:/data/backup
编写备份脚本
#!/bin/sh
today=`date +%Y%m%d`
curl --location --request PUT http://localhost:9200/_snapshot/es_bak --header 'Content-Type: application/json' --data-raw '{"type": "fs","settings":{"compress": true,"location": "/data/backup/es_bak"}}'
curl --location --request PUT http://localhost:9200/_snapshot/es_bak/snapshot_$today
# 等待备份完成
sleep 3600
# 删除旧数据
seven_days_ago=`date -d "7 day ago" +"%Y%m%d"`
curl --location --request DELETE http://localhost:9200/_snapshot/es_bak/snapshot_$seven_days_ago
crontab定时任务
sudo crontab -e
每天凌晨1点执行,最下面添加:
0 1 * * * sh /opt/es-bak.sh