This commit is contained in:
bel
2021-09-14 06:38:09 -06:00
commit 9684eedac7
9 changed files with 180 additions and 0 deletions

4
borg/.gitignore vendored Executable file
View File

@@ -0,0 +1,4 @@
*.sw*
backup/
mnt/
restore/

28
borg/Dockerfile Executable file
View File

@@ -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"]

25
borg/build_and_run.sh Executable file
View File

@@ -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

48
borg/config.yaml Executable file
View File

@@ -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

28
borg/entrypoint.sh Executable file
View File

@@ -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