init consul backup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
vincent 2023-11-01 19:23:49 +01:00
commit 8b0467e240
5 changed files with 78 additions and 0 deletions

24
.drone.yml Normal file
View File

@ -0,0 +1,24 @@
---
kind: pipeline
name: build and publish
steps:
- name: docker
image: plugins/docker
settings:
repo: ducampsv/docker-consul-backup
username:
from_secret: docker_username
password:
from_secret: docker_password
---
kind: secret
name: docker_username
get:
path: secrets/data/droneci/dockerHub
name: username
---
kind: secret
name: docker_password
get:
path: secrets/data/droneci/dockerHub
name: password

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM hashicorp/consul:latest
ENV CONSUL_HTTP_ADDR="http://consul.service.consul:8500"
ENV RETENTION=30
ENV TOKEN_AUTH=""
COPY cs-backup.sh /
CMD ./cs-backup.sh
VOLUME /backup

13
Readme.md Normal file
View File

@ -0,0 +1,13 @@
# docker-consul-backup
perform a backup of consul raft base
## ENV variable
- RETENTION
- CONSUL_HTTP_ADDR
- TOKEN_AUTH
## mount
mount your backup location on /backup

27
cs-backup.sh Executable file
View File

@ -0,0 +1,27 @@
export PATH_SNAPSHOT="/backup"
export PATH_DIR="daily"
export PATH_BACKUP=$PATH_SNAPSHOT"/"$PATH_DIR
export RETENTION=30
export SNAPSHOT_FILE=$(date +%Y-%m-%d)
create_snapshot_folder(){
mkdir -p $PATH_BACKUP
}
run_snapshot() {
/bin/consul snapshot save -token=$TOKEN_AUTH $PATH_BACKUP/$SNAPSHOT_FILE.snap
}
retention() {
find $PATH_BACKUP -name "*.snap" -mtime +${RETENTION} -print -exec rm {} \;
}
main() {
create_snapshot_folder
run_snapshot
retention
}
### START HERE ###
main $@

7
makefile Normal file
View File

@ -0,0 +1,7 @@
DOCKER_ORGANIZATION := ducampsv
DOCKER_IMAGE:= docker-consul-backup
build:
docker buildx build . -t $(DOCKER_ORGANIZATION)/$(DOCKER_IMAGE)