mirror of
https://github.com/ViViDboarder/docker-restic-cron.git
synced 2024-11-23 13:46:35 +00:00
Switch to Alpine
This commit is contained in:
parent
cdc1cfac30
commit
ff7089e27a
37
Dockerfile
37
Dockerfile
@ -1,33 +1,30 @@
|
|||||||
ARG REPO=library
|
ARG REPO=library
|
||||||
FROM ${REPO}/ubuntu:focal
|
FROM ${REPO}/alpine:3.12
|
||||||
LABEL maintainer="ViViDboarder <vividboarder@gmail.com>"
|
LABEL maintainer="ViViDboarder <vividboarder@gmail.com>"
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apk add --no-cache curl=~7 bash=~5
|
||||||
&& apt-get install -y --no-install-recommends \
|
|
||||||
ca-certificates \
|
|
||||||
cron \
|
|
||||||
restic=0.9.6* \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/apt/lists/*
|
|
||||||
|
|
||||||
VOLUME /root/.cache/restic
|
ARG ARCH=amd64
|
||||||
VOLUME /backups
|
|
||||||
|
|
||||||
|
ARG RCLONE_VERSION=v1.55.1
|
||||||
|
|
||||||
|
COPY ./scripts/install_rclone.sh /scripts/
|
||||||
|
RUN /scripts/install_rclone.sh "$RCLONE_VERSION" "$ARCH"
|
||||||
|
|
||||||
|
ARG RESTIC_VERSION=0.12.0
|
||||||
|
|
||||||
|
COPY ./scripts/install_restic.sh /scripts/
|
||||||
|
RUN /scripts/install_restic.sh "$RESTIC_VERSION" "$ARCH"
|
||||||
|
|
||||||
|
# Set some default environment variables
|
||||||
ENV BACKUP_DEST="/backups"
|
ENV BACKUP_DEST="/backups"
|
||||||
ENV BACKUP_NAME="backup"
|
ENV BACKUP_NAME="backup"
|
||||||
ENV PATH_TO_BACKUP="/data"
|
ENV PATH_TO_BACKUP="/data"
|
||||||
|
|
||||||
# Cron schedules
|
|
||||||
ENV CRON_SCHEDULE=""
|
ENV CRON_SCHEDULE=""
|
||||||
ENV VERIFY_CRON_SCHEDULE=""
|
ENV VERIFY_CRON_SCHEDULE=""
|
||||||
|
|
||||||
COPY backup.sh /
|
COPY ./scripts /scripts
|
||||||
COPY restore.sh /
|
|
||||||
COPY start.sh /
|
|
||||||
COPY verify.sh /
|
|
||||||
COPY healthcheck.sh /
|
|
||||||
COPY cron-exec.sh /
|
|
||||||
|
|
||||||
HEALTHCHECK CMD /healthcheck.sh
|
HEALTHCHECK CMD /scripts/healthcheck.sh
|
||||||
|
|
||||||
CMD [ "/start.sh" ]
|
CMD [ "/scripts/start.sh" ]
|
||||||
|
18
Makefile
18
Makefile
@ -1,4 +1,4 @@
|
|||||||
DOCKER_TAG ?= docker-restic-cron
|
DOCKER_TAG ?= docker-restic-cron-$(USER)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: check test-all
|
all: check test-all
|
||||||
@ -15,7 +15,7 @@ build-x86:
|
|||||||
|
|
||||||
.PHONY: build-arm
|
.PHONY: build-arm
|
||||||
build-arm:
|
build-arm:
|
||||||
docker build --build-arg REPO=arm32v7 -f ./Dockerfile -t $(DOCKER_TAG)-arm32v7 .
|
docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm -f ./Dockerfile -t $(DOCKER_TAG)-arm .
|
||||||
|
|
||||||
.PHONY: build-all
|
.PHONY: build-all
|
||||||
build-all: build-x86 build-arm
|
build-all: build-x86 build-arm
|
||||||
@ -25,15 +25,17 @@ test-x86: build-x86
|
|||||||
cd tests && ./test.sh $(DOCKER_TAG)
|
cd tests && ./test.sh $(DOCKER_TAG)
|
||||||
cd tests && ./test-pre-scripts.sh $(DOCKER_TAG)
|
cd tests && ./test-pre-scripts.sh $(DOCKER_TAG)
|
||||||
|
|
||||||
|
.PHONY: test-arm
|
||||||
|
test-arm: build-arm
|
||||||
|
cd tests && ./test.sh $(DOCKER_TAG)-arm
|
||||||
|
cd tests && ./test-pre-scripts.sh $(DOCKER_TAG)-arm
|
||||||
|
|
||||||
.PHONY: test-all
|
.PHONY: test-all
|
||||||
test-all: test-x86 test-arm
|
test-all: test-x86 test-arm
|
||||||
|
|
||||||
.PHONY: test-s3-x86
|
.PHONY: test-s3-x86
|
||||||
test-s3-x86:
|
test-s3-x86:
|
||||||
cd tests && ./test-s3.sh ubuntu
|
cd tests && ./test-s3.sh
|
||||||
|
|
||||||
.PHONY: test-s3-all
|
|
||||||
test-s3-all: test-s3-x86 test-s3-arm
|
|
||||||
|
|
||||||
.PHONY: shell-x86
|
.PHONY: shell-x86
|
||||||
shell-x86: build-x86
|
shell-x86: build-x86
|
||||||
@ -44,7 +46,9 @@ shell: shell-x86
|
|||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
docker-compose -f docker-compose-test-s3.yml down -v
|
docker-compose -f ./tests/docker-compose-test-s3.yml down -v
|
||||||
|
rm -fr my-backups/
|
||||||
|
rm -fr my-data/
|
||||||
|
|
||||||
.PHONY: install-hooks
|
.PHONY: install-hooks
|
||||||
install-hooks:
|
install-hooks:
|
||||||
|
18
scripts/install_rclone.sh
Executable file
18
scripts/install_rclone.sh
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
VERSION="$1"
|
||||||
|
ARCH="$2"
|
||||||
|
|
||||||
|
RCLONE_NAME=rclone-${VERSION}-linux-${ARCH}
|
||||||
|
|
||||||
|
# Download
|
||||||
|
curl -o rclone.zip "https://downloads.rclone.org/${VERSION}/${RCLONE_NAME}.zip"
|
||||||
|
|
||||||
|
# Install
|
||||||
|
unzip rclone.zip
|
||||||
|
mv "${RCLONE_NAME}/rclone" /usr/local/bin/
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
rm rclone.zip
|
||||||
|
rm -fr "${RCLONE_NAME}"
|
15
scripts/install_restic.sh
Executable file
15
scripts/install_restic.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
VERSION="$1"
|
||||||
|
ARCH="$2"
|
||||||
|
|
||||||
|
RESTIC_NAME=restic_${VERSION}_linux_${ARCH}
|
||||||
|
|
||||||
|
# Download
|
||||||
|
curl -L -o restic.bz2 "https://github.com/restic/restic/releases/download/v${VERSION}/${RESTIC_NAME}.bz2"
|
||||||
|
|
||||||
|
# Install
|
||||||
|
bunzip2 -v restic.bz2
|
||||||
|
mv restic /usr/local/bin/
|
||||||
|
chmod +x /usr/local/bin/restic
|
@ -16,12 +16,12 @@ restic -r "$BACKUP_DEST" snapshots || restic -r "$BACKUP_DEST" init
|
|||||||
|
|
||||||
# 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" ] && [ -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 latest
|
/scripts/cron-exec.sh /scripts/restore.sh latest
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Unless explicitly skipping, take a backup on startup
|
# Unless explicitly skipping, take a backup on startup
|
||||||
if [ "$SKIP_ON_START" != "true" ]; then
|
if [ "$SKIP_ON_START" != "true" ]; then
|
||||||
/cron-exec.sh /backup.sh
|
/scripts/cron-exec.sh /scripts/backup.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$CRON_SCHEDULE" ]; then
|
if [ -n "$CRON_SCHEDULE" ]; then
|
||||||
@ -45,8 +45,11 @@ if [ -n "$CRON_SCHEDULE" ]; then
|
|||||||
# Add to crontab
|
# Add to crontab
|
||||||
crontab /crontab.conf
|
crontab /crontab.conf
|
||||||
|
|
||||||
echo "Starting restic cron..."
|
# List crontabs
|
||||||
cron
|
crontab -l
|
||||||
|
|
||||||
|
echo "Starting cron..."
|
||||||
|
crond
|
||||||
|
|
||||||
touch /cron.log
|
touch /cron.log
|
||||||
tail -f /cron.log
|
tail -f /cron.log
|
@ -1,6 +1,7 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
restic \
|
restic \
|
||||||
-r "$BACKUP_DEST" \
|
-r "$BACKUP_DEST" \
|
||||||
$OPT_ARGUMENTS \
|
$OPT_ARGUMENTS \
|
@ -26,5 +26,5 @@ services:
|
|||||||
expose:
|
expose:
|
||||||
- "9000"
|
- "9000"
|
||||||
environment:
|
environment:
|
||||||
MINIO_ACCESS_KEY: SUPER_SECRET_ACCESS_KEY
|
MINIO_ROOT_USER: SUPER_SECRET_ACCESS_KEY
|
||||||
MINIO_SECRET_KEY: SUPER_SECRET_SECRET_KEY
|
MINIO_ROOT_PASSWORD: SUPER_SECRET_SECRET_KEY
|
||||||
|
@ -10,19 +10,20 @@ if [ "$IN_CONTAINER" != "true" ] ; then
|
|||||||
-e SKIP_ON_START=true \
|
-e SKIP_ON_START=true \
|
||||||
-e RESTIC_PASSWORD="Correct.Horse.Battery.Staple" \
|
-e RESTIC_PASSWORD="Correct.Horse.Battery.Staple" \
|
||||||
-v "$(pwd)/test-pre-scripts.sh:/test.sh" \
|
-v "$(pwd)/test-pre-scripts.sh:/test.sh" \
|
||||||
-v "$(pwd)/test-pre-scripts:/scripts" \
|
-v "$(pwd)/test-pre-scripts/backup:/scripts/backup" \
|
||||||
|
-v "$(pwd)/test-pre-scripts/restore:/scripts/restore" \
|
||||||
|
-v "$(pwd)/test-pre-scripts/create-test-data.sql:/scripts/create-test-data.sql" \
|
||||||
"$image" \
|
"$image" \
|
||||||
bash -c "/test.sh"
|
bash -c "/test.sh"
|
||||||
else
|
else
|
||||||
echo "Performing backup tests"
|
echo "Performing backup tests"
|
||||||
|
|
||||||
echo "Verify cron and crontab exist"
|
echo "Verify cron and crontab exist"
|
||||||
type cron
|
type crond
|
||||||
type crontab
|
type crontab
|
||||||
|
|
||||||
echo "Install sqlite3"
|
echo "Install sqlite3"
|
||||||
apt-get update
|
apk add sqlite
|
||||||
apt-get install -y --no-install-recommends sqlite3
|
|
||||||
|
|
||||||
echo "Create test data..."
|
echo "Create test data..."
|
||||||
mkdir -p /data
|
mkdir -p /data
|
||||||
@ -30,10 +31,10 @@ else
|
|||||||
sqlite3 /data/test_database.db < /scripts/create-test-data.sql
|
sqlite3 /data/test_database.db < /scripts/create-test-data.sql
|
||||||
|
|
||||||
echo "Fake a start and init repo"
|
echo "Fake a start and init repo"
|
||||||
CRON_SCHEDULE="" /start.sh
|
CRON_SCHEDULE="" /scripts/start.sh
|
||||||
|
|
||||||
echo "Making backup..."
|
echo "Making backup..."
|
||||||
/backup.sh
|
/scripts/backup.sh
|
||||||
|
|
||||||
echo "Verify intermediary file is gone"
|
echo "Verify intermediary file is gone"
|
||||||
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
|
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
|
||||||
@ -45,7 +46,7 @@ else
|
|||||||
test -f /data/test_database.db && exit 1 || echo "Gone"
|
test -f /data/test_database.db && exit 1 || echo "Gone"
|
||||||
|
|
||||||
echo "Restore backup..."
|
echo "Restore backup..."
|
||||||
/restore.sh latest
|
/scripts/restore.sh latest
|
||||||
|
|
||||||
echo "Verify restored files exist..."
|
echo "Verify restored files exist..."
|
||||||
test -f /data/test_database.db
|
test -f /data/test_database.db
|
||||||
@ -59,7 +60,7 @@ else
|
|||||||
test -f /data/test_database.db && exit 1 || echo "Gone"
|
test -f /data/test_database.db && exit 1 || echo "Gone"
|
||||||
|
|
||||||
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
||||||
RESTORE_ON_EMPTY_START=true /start.sh
|
RESTORE_ON_EMPTY_START=true /scripts/start.sh
|
||||||
|
|
||||||
echo "Verify restore happened..."
|
echo "Verify restore happened..."
|
||||||
test -f /data/test_database.db
|
test -f /data/test_database.db
|
||||||
@ -71,5 +72,5 @@ else
|
|||||||
|
|
||||||
echo "Verify restore with incorrect passphrase fails..."
|
echo "Verify restore with incorrect passphrase fails..."
|
||||||
echo "Fail to restore backup..."
|
echo "Fail to restore backup..."
|
||||||
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /restore.sh latest && exit 1 || echo "OK"
|
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /scripts/restore.sh latest && exit 1 || echo "OK"
|
||||||
fi
|
fi
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
export DOCKER_BASE=$1
|
|
||||||
|
|
||||||
docker-compose -f docker-compose-test-s3.yml up \
|
docker-compose -f docker-compose-test-s3.yml up \
|
||||||
--build --abort-on-container-exit --force-recreate
|
--build --abort-on-container-exit --force-recreate
|
||||||
|
@ -16,23 +16,23 @@ else
|
|||||||
echo "Performing backup tests"
|
echo "Performing backup tests"
|
||||||
|
|
||||||
echo "Verify cron and crontab exist"
|
echo "Verify cron and crontab exist"
|
||||||
type cron
|
type crond
|
||||||
type crontab
|
type crontab
|
||||||
|
|
||||||
echo "Create test data..."
|
echo "Create test data..."
|
||||||
mkdir -p /data && echo Test > /data/test.txt
|
mkdir -p /data && echo Test > /data/test.txt
|
||||||
|
|
||||||
echo "Fake a start and init repo"
|
echo "Fake a start and init repo"
|
||||||
CRON_SCHEDULE="" /start.sh
|
CRON_SCHEDULE="" /scripts/start.sh
|
||||||
|
|
||||||
echo "Making backup..."
|
echo "Making backup..."
|
||||||
/cron-exec.sh /backup.sh || { cat /cron.log && exit 1; }
|
/scripts/cron-exec.sh /scripts/backup.sh || { cat /cron.log && exit 1; }
|
||||||
|
|
||||||
echo "Verify backup..."
|
echo "Verify backup..."
|
||||||
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
/scripts/cron-exec.sh /scripts/verify.sh || { cat /cron.log && exit 1; }
|
||||||
|
|
||||||
echo "Auto cleanup on second backup..."
|
echo "Auto cleanup on second backup..."
|
||||||
CLEANUP_COMMAND="--prune --keep-last 1" /cron-exec.sh /backup.sh || { cat /cron.log && exit 1; }
|
CLEANUP_COMMAND="--prune --keep-last 1" /scripts/cron-exec.sh /scripts/backup.sh || { cat /cron.log && exit 1; }
|
||||||
|
|
||||||
echo "Delete test data..."
|
echo "Delete test data..."
|
||||||
rm -fr /data/*
|
rm -fr /data/*
|
||||||
@ -41,15 +41,15 @@ else
|
|||||||
test -f /data/test.txt && exit 1 || echo "Gone"
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
||||||
|
|
||||||
echo "Restore backup..."
|
echo "Restore backup..."
|
||||||
/cron-exec.sh /restore.sh latest || { cat /cron.log && exit 1; }
|
/scripts/cron-exec.sh /scripts/restore.sh latest || { cat /cron.log && exit 1; }
|
||||||
/healthcheck.sh
|
/scripts/healthcheck.sh
|
||||||
|
|
||||||
echo "Verify restore..."
|
echo "Verify restore..."
|
||||||
test -f /data/test.txt
|
test -f /data/test.txt
|
||||||
cat /data/test.txt
|
cat /data/test.txt
|
||||||
|
|
||||||
echo "Verify backup..."
|
echo "Verify backup..."
|
||||||
/verify.sh
|
/scripts/verify.sh
|
||||||
|
|
||||||
echo "Delete test data again..."
|
echo "Delete test data again..."
|
||||||
rm -fr /data/*
|
rm -fr /data/*
|
||||||
@ -58,8 +58,8 @@ else
|
|||||||
test -f /data/test.txt && exit 1 || echo "Gone"
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
||||||
|
|
||||||
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
||||||
RESTORE_ON_EMPTY_START=true /start.sh || { cat /cron.log && exit 1; }
|
RESTORE_ON_EMPTY_START=true /scripts/start.sh || { cat /cron.log && exit 1; }
|
||||||
/healthcheck.sh || { echo "Failed healthcheck"; cat /cron.log; exit 1; }
|
/scripts/healthcheck.sh || { echo "Failed healthcheck"; cat /cron.log; exit 1; }
|
||||||
|
|
||||||
echo "Verify restore happened..."
|
echo "Verify restore happened..."
|
||||||
test -f /data/test.txt
|
test -f /data/test.txt
|
||||||
@ -67,8 +67,8 @@ else
|
|||||||
|
|
||||||
echo "Verify restore with incorrect passphrase fails..."
|
echo "Verify restore with incorrect passphrase fails..."
|
||||||
echo "Fail to restore backup..."
|
echo "Fail to restore backup..."
|
||||||
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /cron-exec.sh /restore.sh latest && exit 1 || echo "OK"
|
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /scripts/cron-exec.sh /scripts/restore.sh latest && exit 1 || echo "OK"
|
||||||
|
|
||||||
echo "Verify failed healthcheck"
|
echo "Verify failed healthcheck"
|
||||||
/healthcheck.sh && exit 1 || echo "OK"
|
/scripts/healthcheck.sh && exit 1 || echo "OK"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user