Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Add backup scripts, Update to 0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSilkky committed Aug 2, 2023
1 parent 5c9d35d commit 6c71992
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
uses: thesilkky/workflows/.github/workflows/docker-build-push.yml@main
with:
image: thesilkky/restic
image-version: '0.16.0'
context: .
build-args: RESTIC_VERSION=0.16.0
platforms: linux/amd64,linux/arm64
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.vscode
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ARG GO_VERSION=1.20.6
ARG ALPINE_VERSION=3.18
ARG RESTIC_VERSION

####################################################################################################
## Builder
Expand All @@ -10,14 +11,15 @@ FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS

ARG TARGETOS
ARG TARGETARCH
ARG RESTIC_VERSION

ENV CGO_ENABLE=0

RUN apk add --no-cache \
ca-certificates \
git

ADD --keep-git-dir=true https://github.com/restic/restic.git /restic
ADD --keep-git-dir=true https://github.com/restic/restic.git#v${RESTIC_VERSION} /restic

WORKDIR /restic

Expand All @@ -35,11 +37,11 @@ RUN apk add --no-cache \
bash

COPY --from=builder --chmod=755 /output/restic /usr/local/bin
COPY --chmod=755 entrypoint.sh /
COPY --chmod=755 entrypoint.sh backup.sh /

ENTRYPOINT ["/entrypoint.sh"]

CMD ["restic", "--help"]
CMD ["/backup.sh"]

LABEL org.opencontainers.image.source="https://github.com/restic/restic.git"
LABEL org.opencontainers.image.licenses="BSD-2-Clause"
Expand Down
32 changes: 32 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -euo pipefail

start=$(date +%s)
echo "Starting backup: ${RESTIC_BACKUP_SOURCE} to ${RESTIC_REPOSITORY} $(date +"%Y-%m-%d %H:%M:%S")"

set +e
restic backup ${RESTIC_BACKUP_ARGS} "${RESTIC_BACKUP_SOURCE}"
backupRC=$?
set -e

if [[ $backupRC == 0 ]]; then
echo "Backup successful"
else
echo "Backup failed with status: ${backupRC}"
restic unlock
fi

if [[ $backupRC == 0 ]] && [ -n "${RESTIC_FORGET_ARGS}" ]; then
echo "Forgetting old snapshots with: ${RESTIC_FORGET_ARGS}"
if restic forget ${RESTIC_FORGET_ARGS}; then
echo "Forget successful"
else
echo "Forget failed"
restic unlock
fi
fi

end=$(date +%s)
echo "Finished backup at: $(date +"%Y-%m-%d %H:%M:%S") in $((end-start)) seconds."

exit $backupRC
15 changes: 14 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/bin/bash
set -euo pipefail

if [[ -f $INIT_SCRIPT ]]; then
echo "Running init script: ${INIT_SCRIPT}"
source "$INIT_SCRIPT"
fi

echo "Running Restic: $(date)"
echo "Checking repository: ${RESTIC_REPOSITORY}"
if restic cat config > /dev/null; then
echo "Found repository"
else
echo "Initializing repository: ${RESTIC_REPOSITORY}"
if restic init; then
echo "Initialized repository"
else
echo "Failed to initialize repository"
exit 1
fi
fi

exec "$@"

0 comments on commit 6c71992

Please sign in to comment.