mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-04-05 12:48:51 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daf520b039 | ||
|
|
ac17d10585 | ||
|
|
4130af9540 | ||
|
|
f500b08d94 | ||
|
|
fa45e05b19 | ||
|
|
527ba2dd4f | ||
|
|
effd03a102 | ||
|
|
a6a6570d78 | ||
|
|
d9246419f9 | ||
|
|
9a3bf04654 | ||
|
|
1b2d36f3c4 | ||
|
|
bb10ca8b31 | ||
|
|
f081131560 | ||
|
|
0eb6656705 | ||
|
|
918b7f656a | ||
|
|
3b400123d3 | ||
|
|
bf045a4be3 | ||
|
|
9e028df9a7 | ||
|
|
d896924040 | ||
|
|
d0cea127a5 | ||
|
|
013efd00a9 | ||
|
|
bb1d2e202b | ||
|
|
e5f81c232e |
28
Dockerfile
28
Dockerfile
@@ -1,36 +1,36 @@
|
||||
FROM golang:1.7-alpine
|
||||
MAINTAINER info@lobaro.com
|
||||
FROM alpine as certs
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
RUN echo http://nl.alpinelinux.org/alpine/v3.4/community >> /etc/apk/repositories
|
||||
RUN apk add --no-cache git nfs-utils openssh fuse
|
||||
RUN git clone https://github.com/restic/restic \
|
||||
&& cd restic \
|
||||
&& go run build.go \
|
||||
&& cp restic /usr/local/bin/
|
||||
RUN apk del git
|
||||
|
||||
RUN mkdir /mnt/restic
|
||||
FROM busybox:glibc
|
||||
|
||||
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
|
||||
|
||||
# Get restic executable
|
||||
ENV RESTIC_VERSION=0.9.4
|
||||
ADD https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2 /
|
||||
RUN bzip2 -d restic_${RESTIC_VERSION}_linux_amd64.bz2 && mv restic_${RESTIC_VERSION}_linux_amd64 /bin/restic && chmod +x /bin/restic
|
||||
|
||||
RUN mkdir -p /mnt/restic /var/spool/cron/crontabs /var/log
|
||||
|
||||
ENV RESTIC_REPOSITORY=/mnt/restic
|
||||
ENV RESTIC_PASSWORD=""
|
||||
ENV RESTIC_TAG=""
|
||||
ENV NFS_TARGET=""
|
||||
# By default backup every 6 hours
|
||||
ENV BACKUP_CRON="* */6 * * *"
|
||||
ENV BACKUP_CRON="0 */6 * * *"
|
||||
ENV RESTIC_FORGET_ARGS=""
|
||||
ENV RESTIC_JOB_ARGS=""
|
||||
|
||||
# /data is the dir where you have to put the data to be backed up
|
||||
VOLUME /data
|
||||
|
||||
COPY backup.sh /bin/backup
|
||||
RUN chmod +x /bin/backup
|
||||
|
||||
COPY entry.sh /entry.sh
|
||||
|
||||
RUN touch /var/log/cron.log
|
||||
|
||||
WORKDIR "/"
|
||||
|
||||
#ENTRYPOINT ["ls"]
|
||||
ENTRYPOINT ["/entry.sh"]
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ Latest (experimental)
|
||||
docker pull lobaro/restic-backup-docker
|
||||
```
|
||||
|
||||
Please don't hesitate to report any issue you find. **Thanks.**
|
||||
|
||||
# Test the container
|
||||
|
||||
Clone this repository
|
||||
@@ -66,12 +68,15 @@ The container is setup by setting [environment variables](https://docs.docker.co
|
||||
|
||||
## Environment variables
|
||||
|
||||
* `RESTIC_REPOSITORY` - the location of the restic repository. Default `/mnt/restic`
|
||||
* `RESTIC_REPOSITORY` - the location of the restic repository. Default `/mnt/restic`. For S3: `s3:https://s3.amazonaws.com/BUCKET_NAME`
|
||||
* `RESTIC_PASSWORD` - the password for the restic repository. Will also be used for restic init during first start when the repository is not initialized.
|
||||
* `RESTIC_TAG` - Optional. To tag the images created by the container.
|
||||
* `NFS_TARGET` - Optional. If set the given NFS is mounted, i.e. `mount -o nolock -v ${NFS_TARGET} /mnt/restic`. `RESTIC_REPOSITORY` must remain it's default value!
|
||||
* `BACKUP_CRON` - A cron expression to run the backup. Default: `* */6 * * *` aka every 6 hours.
|
||||
* `BACKUP_CRON` - A cron expression to run the backup. Note: cron daemon uses UTC time zone. Default: `0 */6 * * *` aka every 6 hours.
|
||||
* `RESTIC_FORGET_ARGS` - Optional. Only if specified `restic forget` is run with the given arguments after each backup. Example value: `-e "RESTIC_FORGET_ARGS=--prune --keep-last 10 --keep-hourly 24 --keep-daily 7 --keep-weekly 52 --keep-monthly 120 --keep-yearly 100"`
|
||||
* `RESTIC_JOB_ARGS` - Optional. Allows to specify extra arguments to the back up job such as limiting bandwith with `--limit-upload` or excluding file masks with `--exclude`.
|
||||
* `AWS_ACCESS_KEY_ID` - Optional. When using restic with AWS S3 storage.
|
||||
* `AWS_SECRET_ACCESS_KEY` - Optional. When using restic with AWS S3 storage.
|
||||
|
||||
## Volumes
|
||||
|
||||
|
||||
9
backup.sh
Normal file → Executable file
9
backup.sh
Normal file → Executable file
@@ -17,10 +17,12 @@ echo "Starting Backup at $(date)" >> ${lastLogfile}
|
||||
logLast "BACKUP_CRON: ${BACKUP_CRON}"
|
||||
logLast "RESTIC_TAG: ${RESTIC_TAG}"
|
||||
logLast "RESTIC_FORGET_ARGS: ${RESTIC_FORGET_ARGS}"
|
||||
|
||||
logLast "RESTIC_JOB_ARGS: ${RESTIC_JOB_ARGS}"
|
||||
logLast "RESTIC_REPOSITORY: ${RESTIC_REPOSITORY}"
|
||||
logLast "AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}"
|
||||
|
||||
# Do not save full backup log to logfile but to backup-last.log
|
||||
restic backup /data --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1
|
||||
restic backup /data ${RESTIC_JOB_ARGS} --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1
|
||||
rc=$?
|
||||
logLast "Finished backup at $(date)"
|
||||
if [[ $rc == 0 ]]; then
|
||||
@@ -29,6 +31,7 @@ else
|
||||
echo "Backup Failed with Status ${rc}"
|
||||
restic unlock
|
||||
copyErrorLog
|
||||
kill 1
|
||||
fi
|
||||
|
||||
if [ -n "${RESTIC_FORGET_ARGS}" ]; then
|
||||
@@ -46,4 +49,4 @@ if [ -n "${RESTIC_FORGET_ARGS}" ]; then
|
||||
fi
|
||||
|
||||
end=`date +%s`
|
||||
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end-start)) sconds"
|
||||
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end-start)) seconds"
|
||||
|
||||
6
entry.sh
6
entry.sh
@@ -3,6 +3,12 @@ set -e
|
||||
|
||||
echo "Starting container ..."
|
||||
|
||||
RESTIC_CMD=restic
|
||||
|
||||
if [ -n "${ROOT_CERT}" ]; then
|
||||
RESTIC_CMD="${RESTIC_CMD} --cert ${ROOT_CERT}"
|
||||
fi
|
||||
|
||||
if [ -n "${NFS_TARGET}" ]; then
|
||||
echo "Mounting NFS based on NFS_TARGET: ${NFS_TARGET}"
|
||||
mount -o nolock -v ${NFS_TARGET} /mnt/restic
|
||||
|
||||
Reference in New Issue
Block a user