2021-04-02 13:59:47 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Copyright 2021 - Offen Authors <hioffen@posteo.de>
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
# Portions of this file are taken from github.com/futurice/docker-volume-backup
|
|
|
|
# See NOTICE for information about authors and licensing.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Write cronjob env to file, fill in sensible defaults, and read them back in
|
|
|
|
cat <<EOF > env.sh
|
|
|
|
BACKUP_SOURCES="${BACKUP_SOURCES:-/backup}"
|
|
|
|
BACKUP_CRON_EXPRESSION="${BACKUP_CRON_EXPRESSION:-@daily}"
|
2021-08-19 09:25:53 +02:00
|
|
|
BACKUP_FILENAME="${BACKUP_FILENAME:-backup-%Y-%m-%dT%H-%M-%S.tar.gz}"
|
|
|
|
BACKUP_ARCHIVE="${BACKUP_ARCHIVE:-/archive}"
|
2021-04-02 13:59:47 +02:00
|
|
|
|
|
|
|
BACKUP_RETENTION_DAYS="${BACKUP_RETENTION_DAYS:-}"
|
2021-04-08 08:17:55 +02:00
|
|
|
BACKUP_PRUNING_LEEWAY="${BACKUP_PRUNING_LEEWAY:-10m}"
|
2021-08-19 09:25:53 +02:00
|
|
|
BACKUP_STOP_CONTAINER_LABEL="${BACKUP_STOP_CONTAINER_LABEL:-true}"
|
2021-04-02 13:59:47 +02:00
|
|
|
|
|
|
|
AWS_S3_BUCKET_NAME="${AWS_S3_BUCKET_NAME:-}"
|
|
|
|
AWS_ENDPOINT="${AWS_ENDPOINT:-s3.amazonaws.com}"
|
2021-07-09 09:21:42 +02:00
|
|
|
AWS_ENDPOINT_PROTO="${AWS_ENDPOINT_PROTO:-https}"
|
2021-04-02 13:59:47 +02:00
|
|
|
|
|
|
|
GPG_PASSPHRASE="${GPG_PASSPHRASE:-}"
|
2021-05-24 20:34:30 +02:00
|
|
|
|
2021-05-25 07:35:21 +02:00
|
|
|
MC_GLOBAL_OPTIONS="${MC_GLOBAL_OPTIONS:-}"
|
2021-04-02 13:59:47 +02:00
|
|
|
EOF
|
|
|
|
chmod a+x env.sh
|
|
|
|
source env.sh
|
|
|
|
|
2021-08-19 09:25:53 +02:00
|
|
|
if [ ! -z "$AWS_ACCESS_KEY_ID" ] && [ ! -z "$AWS_SECRET_ACCESS_KEY" ]; then
|
|
|
|
mc $MC_GLOBAL_OPTIONS alias set backup-target \
|
|
|
|
"$AWS_ENDPOINT_PROTO://$AWS_ENDPOINT" \
|
|
|
|
"$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
|
|
|
|
fi
|
2021-04-02 13:59:47 +02:00
|
|
|
|
|
|
|
# Add our cron entry, and direct stdout & stderr to Docker commands stdout
|
2021-04-03 09:33:11 +02:00
|
|
|
echo "Installing cron.d entry with expression $BACKUP_CRON_EXPRESSION."
|
2021-04-02 13:59:47 +02:00
|
|
|
echo "$BACKUP_CRON_EXPRESSION backup 2>&1" | crontab -
|
|
|
|
|
|
|
|
# Let cron take the wheel
|
2021-04-03 09:33:11 +02:00
|
|
|
echo "Starting cron in foreground."
|
2021-04-02 13:59:47 +02:00
|
|
|
crond -f -l 8
|