commit 8b0467e24052b21733335a1ed80d658c19ce9f88 Author: vincent Date: Wed Nov 1 19:23:49 2023 +0100 init consul backup diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..cf30727 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a15603a --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..80e7a92 --- /dev/null +++ b/Readme.md @@ -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 diff --git a/cs-backup.sh b/cs-backup.sh new file mode 100755 index 0000000..590e8fb --- /dev/null +++ b/cs-backup.sh @@ -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 $@ diff --git a/makefile b/makefile new file mode 100644 index 0000000..1dfa904 --- /dev/null +++ b/makefile @@ -0,0 +1,7 @@ + +DOCKER_ORGANIZATION := ducampsv +DOCKER_IMAGE:= docker-consul-backup + + +build: + docker buildx build . -t $(DOCKER_ORGANIZATION)/$(DOCKER_IMAGE)