mirror of
https://github.com/ViViDboarder/docker-duplicity-cron.git
synced 2024-11-23 18:36:30 +00:00
Add pre-commit and clean up
This commit is contained in:
parent
6d460b176f
commit
8d6ffea6b3
17
.pre-commit-config.yaml
Normal file
17
.pre-commit-config.yaml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v2.4.0
|
||||||
|
hooks:
|
||||||
|
- id: check-added-large-files
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- id: mixed-line-ending
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
|
- id: check-symlinks
|
||||||
|
- id: check-case-conflict
|
||||||
|
- repo: git://github.com/jumanjihouse/pre-commit-hooks
|
||||||
|
rev: 1.11.0
|
||||||
|
hooks:
|
||||||
|
- id: shellcheck
|
@ -4,6 +4,7 @@ services: docker
|
|||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||||
|
- pip install pre-commit
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make all
|
- make check all
|
||||||
|
14
Dockerfile
14
Dockerfile
@ -36,13 +36,17 @@ VOLUME /var/lock/duplicity
|
|||||||
|
|
||||||
ENV BACKUP_DEST="file:///backups"
|
ENV BACKUP_DEST="file:///backups"
|
||||||
ENV BACKUP_NAME="backup"
|
ENV BACKUP_NAME="backup"
|
||||||
ENV PATH_TO_BACKUP="/data"
|
ENV CLEANUP_COMMAND=""
|
||||||
ENV PASSPHRASE="Correct.Horse.Battery.Staple"
|
|
||||||
ENV FLOCK_WAIT=60
|
|
||||||
|
|
||||||
# Cron schedules
|
|
||||||
ENV CRON_SCHEDULE=""
|
ENV CRON_SCHEDULE=""
|
||||||
|
ENV FLOCK_WAIT=60
|
||||||
ENV FULL_CRON_SCHEDULE=""
|
ENV FULL_CRON_SCHEDULE=""
|
||||||
|
ENV GPG_KEY_ID=""
|
||||||
|
ENV OPT_ARGUMENTS=""
|
||||||
|
ENV PASSPHRASE="Correct.Horse.Battery.Staple"
|
||||||
|
ENV PATH_TO_BACKUP="/data"
|
||||||
|
ENV RESTORE_ON_EMPTY_START=""
|
||||||
|
ENV SKIP_ON_START=""
|
||||||
|
ENV VERIFY_CRON_SCHEDULE=""
|
||||||
ENV VERIFY_CRON_SCHEDULE=""
|
ENV VERIFY_CRON_SCHEDULE=""
|
||||||
|
|
||||||
# Create script dirs
|
# Create script dirs
|
||||||
|
4
Makefile
4
Makefile
@ -9,6 +9,10 @@ all: build-all test-all test-s3-all
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: test-amd64
|
test: test-amd64
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check:
|
||||||
|
pre-commit run --all-files
|
||||||
|
|
||||||
.PHONY: build-amd64
|
.PHONY: build-amd64
|
||||||
build-amd64:
|
build-amd64:
|
||||||
docker build --build-arg REPO=library -f ./Dockerfile -t $(DOCKER_TAG):amd64 .
|
docker build --build-arg REPO=library -f ./Dockerfile -t $(DOCKER_TAG):amd64 .
|
||||||
|
33
backup.sh
33
backup.sh
@ -1,39 +1,48 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -euf
|
||||||
|
|
||||||
|
BACKUP_CMD=""
|
||||||
|
if test $# -gt 0; then
|
||||||
|
BACKUP_CMD="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
if ! flock -x -w $FLOCK_WAIT 200 ; then
|
if ! flock -x -w "$FLOCK_WAIT" 200 ; then
|
||||||
echo 'ERROR: Could not obtain lock. Exiting.'
|
echo 'ERROR: Could not obtain lock. Exiting.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run pre-backup scripts
|
# Run pre-backup scripts
|
||||||
for f in /scripts/backup/before/*; do
|
for f in /scripts/backup/before/*; do
|
||||||
if [ -f $f -a -x $f ]; then
|
if [ -f "$f" ] && [ -x "$f" ]; then
|
||||||
bash $f
|
bash "$f"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Intentionally not wrapping BACKUP_CMD and OPT_ARGUMENTS
|
||||||
|
# shellcheck disable=SC2086
|
||||||
duplicity \
|
duplicity \
|
||||||
$1 \
|
$BACKUP_CMD \
|
||||||
--asynchronous-upload \
|
--asynchronous-upload \
|
||||||
--log-file /root/duplicity.log \
|
--log-file /root/duplicity.log \
|
||||||
--name $BACKUP_NAME \
|
--name "$BACKUP_NAME" \
|
||||||
$OPT_ARGUMENTS \
|
$OPT_ARGUMENTS \
|
||||||
$PATH_TO_BACKUP \
|
"$PATH_TO_BACKUP" \
|
||||||
$BACKUP_DEST
|
"$BACKUP_DEST"
|
||||||
|
|
||||||
if [ -n "$CLEANUP_COMMAND" ]; then
|
if [ -n "$CLEANUP_COMMAND" ]; then
|
||||||
|
# Intentionally not wrapping CLEANUP_COMMAND
|
||||||
|
# shellcheck disable=SC2086
|
||||||
duplicity $CLEANUP_COMMAND \
|
duplicity $CLEANUP_COMMAND \
|
||||||
--log-file /root/duplicity.log \
|
--log-file /root/duplicity.log \
|
||||||
--name $BACKUP_NAME \
|
--name "$BACKUP_NAME" \
|
||||||
$BACKUP_DEST
|
"$BACKUP_DEST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run post-backup scripts
|
# Run post-backup scripts
|
||||||
for f in /scripts/backup/after/*; do
|
for f in /scripts/backup/after/*; do
|
||||||
if [ -f $f -a -x $f ]; then
|
if [ -f "$f" ] && [ -x "$f" ]; then
|
||||||
bash $f
|
bash "$f"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
13
cron-exec.sh
13
cron-exec.sh
@ -4,8 +4,15 @@ ENV=/env.sh
|
|||||||
LOG=/cron.log
|
LOG=/cron.log
|
||||||
HEALTH_FILE=/unhealthy
|
HEALTH_FILE=/unhealthy
|
||||||
|
|
||||||
touch $ENV
|
if [ -f "$ENV" ]; then
|
||||||
source $ENV
|
# shellcheck disable=SC1090
|
||||||
|
source "$ENV"
|
||||||
|
fi
|
||||||
|
|
||||||
# Execute command and write output to log
|
# Execute command and write output to log
|
||||||
$@ 2>> $LOG && rm -f $HEALTH_FILE || { touch $HEALTH_FILE; exit 1; }
|
if eval "$@" 2>> "$LOG"; then
|
||||||
|
rm -f "$HEALTH_FILE"
|
||||||
|
else
|
||||||
|
touch "$HEALTH_FILE"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
@ -2,4 +2,8 @@
|
|||||||
|
|
||||||
HEALTH_FILE=/unhealthy
|
HEALTH_FILE=/unhealthy
|
||||||
|
|
||||||
test -f $HEALTH_FILE || exit 0 && exit 1
|
if [ -f "$HEALTH_FILE" ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
22
restore.sh
22
restore.sh
@ -1,32 +1,34 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -euf
|
||||||
|
|
||||||
(
|
(
|
||||||
if ! flock -x -w $FLOCK_WAIT 200 ; then
|
if ! flock -x -w "$FLOCK_WAIT" 200 ; then
|
||||||
echo 'ERROR: Could not obtain lock. Exiting.'
|
echo 'ERROR: Could not obtain lock. Exiting.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run pre-restore scripts
|
# Run pre-restore scripts
|
||||||
for f in /scripts/restore/before/*; do
|
for f in /scripts/restore/before/*; do
|
||||||
if [ -f $f -a -x $f ]; then
|
if [ -f "$f" ] && [ -x "$f" ]; then
|
||||||
bash $f
|
bash "$f"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Intentionally not wrapping OPT_ARGUMENTS
|
||||||
|
# shellcheck disable=SC2086
|
||||||
duplicity restore \
|
duplicity restore \
|
||||||
--force \
|
--force \
|
||||||
--log-file /root/duplicity.log \
|
--log-file /root/duplicity.log \
|
||||||
--name $BACKUP_NAME \
|
--name "$BACKUP_NAME" \
|
||||||
$OPT_ARGUMENTS \
|
$OPT_ARGUMENTS \
|
||||||
$@ \
|
"$@" \
|
||||||
$BACKUP_DEST \
|
"$BACKUP_DEST" \
|
||||||
$PATH_TO_BACKUP
|
"$PATH_TO_BACKUP"
|
||||||
|
|
||||||
# Run post-restore scripts
|
# Run post-restore scripts
|
||||||
for f in /scripts/restore/after/*; do
|
for f in /scripts/restore/after/*; do
|
||||||
if [ -f $f -a -x $f ]; then
|
if [ -f "$f" ] && [ -x "$f" ]; then
|
||||||
bash $f
|
bash "$f"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
9
start.sh
9
start.sh
@ -1,23 +1,24 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
set -euf
|
||||||
|
|
||||||
# If first arg is bash, we'll just execute directly
|
# If first arg is bash, we'll just execute directly
|
||||||
if [ "$1" == "bash" ]; then
|
if [ $# -gt 0 ] && [ "$1" == "bash" ]; then
|
||||||
exec "$@"
|
exec "$@"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If no env variable set, get from command line
|
# If no env variable set, get from command line
|
||||||
if [ "$OPT_ARGUMENTS" == "" ]; then
|
if [ "$OPT_ARGUMENTS" == "" ]; then
|
||||||
export OPT_ARGUMENTS="$@"
|
export OPT_ARGUMENTS="$*"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If key id is provied add arg
|
# If key id is provied add arg
|
||||||
if [ -e "$GPG_KEY_ID" ]; then
|
if [ -n "$GPG_KEY_ID" ]; then
|
||||||
export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
|
export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If set to restore on start, restore if the data volume is empty
|
# If set to restore on start, restore if the data volume is empty
|
||||||
if [ "$RESTORE_ON_EMPTY_START" == "true" -a -z "$(ls -A $PATH_TO_BACKUP)" ]; then
|
if [ "$RESTORE_ON_EMPTY_START" == "true" ] && [ -z "$(ls -A "$PATH_TO_BACKUP")" ]; then
|
||||||
/cron-exec.sh /restore.sh
|
/cron-exec.sh /restore.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cd /data
|
cd /data
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cd /data
|
cd /data
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cd /data
|
cd /data
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Don't really need to do anything here
|
# Don't really need to do anything here
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -euf
|
||||||
|
|
||||||
image="$1"
|
|
||||||
|
|
||||||
if [ "$IN_CONTAINER" != "true" ] ; then
|
if [ -z "${IN_CONTAINER+x}" ] ; then
|
||||||
# Run the test script within the container
|
# Run the test script within the container
|
||||||
|
image="$1"
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-e IN_CONTAINER=true \
|
-e IN_CONTAINER=true \
|
||||||
-e SKIP_ON_START=true \
|
-e SKIP_ON_START=true \
|
||||||
@ -31,7 +31,7 @@ else
|
|||||||
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
||||||
|
|
||||||
echo "Delete test data..."
|
echo "Delete test data..."
|
||||||
rm -fr /data/*
|
rm -fr /data/test.txt
|
||||||
|
|
||||||
echo "Verify deleted..."
|
echo "Verify deleted..."
|
||||||
test -f /data/test.txt && exit 1 || echo "Gone"
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
||||||
@ -48,7 +48,7 @@ else
|
|||||||
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
||||||
|
|
||||||
echo "Delete test data again..."
|
echo "Delete test data again..."
|
||||||
rm -fr /data/*
|
rm -fr /data/test.txt
|
||||||
|
|
||||||
echo "Verify deleted..."
|
echo "Verify deleted..."
|
||||||
test -f /data/test.txt && exit 1 || echo "Gone"
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
||||||
|
10
verify.sh
10
verify.sh
@ -1,10 +1,12 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -euf
|
||||||
|
|
||||||
|
# Intentionally not wrapping OPT_ARGUMENTS
|
||||||
|
# shellcheck disable=SC2086
|
||||||
duplicity verify \
|
duplicity verify \
|
||||||
--compare-data \
|
--compare-data \
|
||||||
--log-file /root/duplicity.log \
|
--log-file /root/duplicity.log \
|
||||||
--name $BACKUP_NAME \
|
--name "$BACKUP_NAME" \
|
||||||
$OPT_ARGUMENTS \
|
$OPT_ARGUMENTS \
|
||||||
$BACKUP_DEST \
|
"$BACKUP_DEST" \
|
||||||
$PATH_TO_BACKUP
|
"$PATH_TO_BACKUP"
|
||||||
|
Loading…
Reference in New Issue
Block a user