commit 9684eedac795194ae768bbcb7cfa59b3afacfb6c Author: bel Date: Tue Sep 14 06:38:09 2021 -0600 archive diff --git a/borg/.gitignore b/borg/.gitignore new file mode 100755 index 0000000..58646e1 --- /dev/null +++ b/borg/.gitignore @@ -0,0 +1,4 @@ +*.sw* +backup/ +mnt/ +restore/ diff --git a/borg/Dockerfile b/borg/Dockerfile new file mode 100755 index 0000000..03627df --- /dev/null +++ b/borg/Dockerfile @@ -0,0 +1,28 @@ +FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29 + +RUN apk update && apk add --no-cache \ + python3 \ + curl \ + bash + +WORKDIR /opt +RUN curl -L \ + https://github.com/borgbackup/borg/releases/download/1.1.9/borg-linux64 \ + > ./borg \ + && chmod +x ./borg +RUN pip3 install --upgrade borgmatic \ + && generate-borgmatic-config \ + && cp /etc/borgmatic/config.yaml /etc/borgmatic/sample.config.yaml +RUN mkdir -p /backup /mnt + +VOLUME /etc/borgmatic/ +VOLUME /mnt +VOLUME /backup + +ENV BORG_PASSPHRASE=a + +COPY ./entrypoint.sh ./entrypoint.sh +COPY ./config.yaml /etc/borgmatic/config.yaml + +CMD [] +ENTRYPOINT ["bash", "entrypoint.sh"] diff --git a/borg/build_and_run.sh b/borg/build_and_run.sh new file mode 100755 index 0000000..c7b717e --- /dev/null +++ b/borg/build_and_run.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +set -e +set -u + +cd "$(dirname "${BASH_SOURCE[0]}")" >&2 + +mkdir -p ./{restore,mnt,backup} >&2 + +img="${IMG:-dev:dev}" + +docker build -t $img . >&2 + +if [ -z "${BUILD:-""}" ]; then +docker run \ + --rm \ + -it \ + -e BORG_PASSPHRASE="${BORG_PASSPHRASE:-"a"}" \ + -v $PWD/restore:/opt/mnt \ + -v $PWD/mnt:/mnt \ + -v $PWD/backup:/backup \ + -v $PWD/config.yaml:/etc/borgmatic/config.yaml:ro \ + $img \ + "$@" +fi diff --git a/borg/config.yaml b/borg/config.yaml new file mode 100755 index 0000000..f52315e --- /dev/null +++ b/borg/config.yaml @@ -0,0 +1,48 @@ +location: + source_directories: + - /mnt + repositories: + #- user@backupserver:sourcehostname.borg # ssh example + - /backup + exclude_if_present: .nobackup # do not back up dirs containing X + local_path: /opt/borg + + #exclude_patterns: + # - '*.pyc' + # - ~/*/.cache + # - /etc/ssl + #exclude_from: + # - /etc/borgmatic/excludes + + +storage: + checkpoint_interval: 600 # checkpoint every X seconds during backup + compression: lz4 + + #remote_rate_limit: 100 # KB per Sec + #ssh_command: ssh -i /path/to/private/key + #archive_name_format: '{hostname}-documents-{now}' # borg help placeholders + +retention: + keep_daily: 7 + + #keep_within: 3H # Keep all archives within this time interval. + #keep_secondly: 60 + #keep_minutely: 60 + #keep_hourly: 24 + #keep_weekly: 4 + #keep_monthly: 6 + #keep_yearly: 1 + +#hooks: + #before_backup: + # - echo "Starting a backup job." + #after_backup: + # - echo "Backup created." + #on_error: + # - echo "Error while creating a backup." + +consistency: + checks: + - repository + #- disabled diff --git a/borg/entrypoint.sh b/borg/entrypoint.sh new file mode 100755 index 0000000..c51937f --- /dev/null +++ b/borg/entrypoint.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +function main() { + set -e + set -u + + Borgmatic --init --encryption repokey --verbosity 1 >&2 || true + if [ "$#" -gt 0 ]; then + Borgmatic "$@" + else + Borgmatic --prune --verbosity 1 + Borgmatic --create --progress --verbosity 1 + Borgmatic --check --verbosity 1 # expensive + fi +} + +function Borgmatic() { + log borgmatic "$@" + borgmatic "$@" +} + +function log() { + echo "[$(date +%Y-%m-%d-%H:%M:%S)] $@" >&2 +} + +if [ "$0" == "${BASH_SOURCE[0]}" ]; then + main "$@" +fi diff --git a/restic/.dockerignore b/restic/.dockerignore new file mode 100755 index 0000000..c1e0e6c --- /dev/null +++ b/restic/.dockerignore @@ -0,0 +1 @@ +mnt diff --git a/restic/Dockerfile b/restic/Dockerfile new file mode 100755 index 0000000..4c55fef --- /dev/null +++ b/restic/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.12.5-alpine3.9 as rbuilder + +ENV GOPATH=/go +RUN apk add --no-cache git bash ca-certificates +RUN go get github.com/restic/restic +WORKDIR /go/src/github.com/restic/restic/cmd/restic +RUN git checkout v0.9.5 +RUN CGO_ENABLED=0 go build -o /go/bin/restic -a -installsuffix cgo + +FROM alpine:3.9 + +WORKDIR /main +RUN apk add --no-cache ca-certificates bash +COPY --from=rbuilder /go/bin/ /main + +VOLUME /mnt +RUN echo \ + 'out="$(/main/restic init /mnt 2>&1 | grep -v config.file.already.exists | grep -v created.restic.repository | tr -d "\\n" )"; if test -n "$out"; then printf "ERR: $out\n"; else exec /main/restic "$@"; fi' \ + > /entrypoint.sh \ + && chmod +x /entrypoint.sh +CMD [] +ENTRYPOINT ["bash", "/entrypoint.sh"] diff --git a/restic/build.sh b/restic/build.sh new file mode 100755 index 0000000..72a05da --- /dev/null +++ b/restic/build.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +set -e +cd "$(dirname "${BASH_SOURCE[0]}")" + +IMG=bel/restic:v0.0 + +docker build -t $IMG . +mkdir -p ./mnt +docker run \ + --rm \ + -it \ + -v $PWD/mnt:/mnt \ + $MNT \ + $IMG \ + "$@" diff --git a/restic/sample.sh b/restic/sample.sh new file mode 100755 index 0000000..fdd4dbc --- /dev/null +++ b/restic/sample.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +MNT="-e RCLONE_BWLIMIT=4.5mb -e RESTIC_REPOSITORY=/mnt -e RESTIC_PASSWORD=test -v $HOME:/src" \ + bash build.sh \ + backup \ + /src/Go/src/local/dockers/cal \ + -v \ + --exclude "**/mnt/"