29 Commits

Author SHA1 Message Date
Tobias Kaupat
daf520b039 Update Dockerfile 2019-02-06 12:27:52 +01:00
Tobias Kaupat
ac17d10585 Update README.md
document AWS S3 parameters
2019-02-06 11:33:15 +01:00
Tobias Kaupat
4130af9540 Update backup.sh
log restic repository and AWS ID
2019-02-06 11:20:16 +01:00
Sergei Silnov
f500b08d94 Update to version 0.9.3 2018-10-22 22:44:44 +02:00
Tobias Kaupat
fa45e05b19 Update README.md 2018-07-01 20:24:48 +02:00
Tobias Kaupat
527ba2dd4f Merge pull request #19 from NickBusey/master
Fixing default cron value
2018-07-01 20:16:44 +02:00
Nick Busey
effd03a102 Fixing cron 2018-06-20 15:43:55 -06:00
Tobias Kaupat
a6a6570d78 Merge pull request #16 from KalleDK/patch-1
Update Dockerfile
2018-06-05 20:06:08 +02:00
Kalle Møller
d9246419f9 Update Dockerfile
No reason to run an update when cache wouldn't be used anyways
2018-06-05 17:36:15 +02:00
Tobias Kaupat
9a3bf04654 Merge pull request #13 from mulmschneider/patch-1
Fix typo in variable name
2018-02-26 17:07:21 +01:00
Martin Ulmschneider
1b2d36f3c4 Fix typo in variable name
VERION->VERSION
2018-02-24 23:16:21 +01:00
Tobias Kaupat
bb10ca8b31 Merge pull request #12 from xoes/master
Some Improvements (from my Point of View)
2018-02-12 14:53:55 +01:00
David Arnold
f081131560 [FIX] get root cert into the busybox 2018-02-11 16:50:04 -05:00
David Arnold
0eb6656705 [FIX] use BusyBox with glibc for the remaining dynamically linked libs 2018-02-11 16:50:04 -05:00
David Arnold
918b7f656a [IMP] kill service if sync fails
This, used in combination with a scheduler, clearly marks "problem" to the
cluster operator
2018-02-11 16:50:04 -05:00
David Arnold
3b400123d3 [REF] base on busybox 2018-02-11 16:50:04 -05:00
David Arnold
bf045a4be3 [CLEAN] bakcup is already git update-index --chmod=+xed 2018-02-11 16:50:04 -05:00
David Arnold
9e028df9a7 [IMP] implement two stage build 2018-02-11 12:17:53 -05:00
Tobias Kaupat
d896924040 Merge pull request #11 from stas2k/master
Update to latest golang, add RESTIC_JOB_ARGS
2018-02-04 15:06:07 +01:00
Stas
d0cea127a5 add RESTIC_JOB_ARGS env variable to specify extra restic options 2018-02-03 21:51:17 +01:00
Stas
013efd00a9 clatify container UTC time zone 2018-02-03 21:48:38 +01:00
Stas
bb1d2e202b update to latest golang base 2018-02-03 21:44:02 +01:00
Tobias Kaupat
e5f81c232e Update backup.sh 2018-01-29 22:31:36 +01:00
lobaro-demo
d0cafd0ec9 Fix working dir 2017-04-28 09:15:02 +00:00
Tobias Kaupat
6e8f00b5b3 Update README.md 2017-04-14 01:33:19 +02:00
lobaro-demo
d53bc0a4a5 Use golang:1.7-alpine container 2017-04-03 13:37:18 +00:00
lobaro-demo
8ba9fb4a8f Do not run spearate prune, but let the user use --prune in RESTIC_FORGET_ARGS 2017-04-03 13:22:18 +00:00
Tobias Kaupat
0490f182d5 Update README.md
Explain the new logging mechanisms
2017-02-14 10:54:27 +01:00
lobaro-demo
ca25a281d3 Execute prune after forget, Improove logging
- Log start and end with total duration
- Copy backup-last.log to backup-error-last.log after fail
2017-02-14 09:44:42 +00:00
5 changed files with 83 additions and 26 deletions

View File

@@ -1,32 +1,36 @@
FROM gliderlabs/alpine:3.3
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 go 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 go
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 ["/entry.sh"]

View File

@@ -9,10 +9,18 @@ This container runs restic backups in regular intervals.
**Container**: [lobaro/restic-backup-docker](https://hub.docker.com/r/lobaro/restic-backup-docker/)
Stable
```
docker pull lobaro/restic-backup-docker:v1.0
```
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
@@ -45,14 +53,14 @@ docker exec -ti backup-test /bin/sh
Now you can use restic [as documented](https://restic.readthedocs.io/en/stable/Manual/), e.g. try to run `restic snapshots` to list all your snapshots.
## Logfiles
Logfiles inside the container:
Logfiles are inside the container. If needed you can create volumes for them.
```
docker logs
```
Shows `/var/log/cron.log`
Additionally you can see the the full log of the last `backup` and `forget` command in `/var/log/backup-last.log` inside the container.
Additionally you can see the the full log, including restic output, of the last execution in `/var/log/backup-last.log`. When the backup fails the log is copied to `/var/log/restic-error-last.log`.
# Customize the Container
@@ -60,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.
* `RESTIC_FORGET_ARGS` - Optional. Only if specified `restic forget` is run with the given arguments after each backup. Example value: `-e "RESTIC_FORGET_ARGS=--keep-last 10 --keep-hourly 24 --keep-daily 7 --keep-weekly 52 --keep-monthly 120 --keep-yearly 100"`
* `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
@@ -87,6 +98,16 @@ Now you can simply specify the restic repository to be an [SFTP repository](http
-e "RESTIC_REPOSITORY=sftp:user@host:/tmp/backup"
```
# TODO
# Changelog
* Add testsetup based on docker-compose
Versioning follows [Semantic versioning](http://semver.org/)
! Breaking changes
**:latest**
* ! `--prune` must be passed to `RESTIC_FORGET_ARGS` to execute prune after forget.
* Switch to base Docker container to `golang:1.7-alpine` to support latest restic build.
**:v1.0**
* First stable version

35
backup.sh Normal file → Executable file
View File

@@ -1,27 +1,52 @@
#!/bin/sh
echo "Starting Backup"
lastLogfile="/var/log/backup-last.log"
copyErrorLog() {
cp ${lastLogfile} /var/log/backup-error-last.log
}
logLast() {
echo "$1" >> ${lastLogfile}
}
start=`date +%s`
rm -f ${lastLogfile}
echo "Starting Backup at $(date +"%Y-%m-%d %H:%M:%S")"
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"} > /var/log/backup-last.log 2>&1
restic backup /data ${RESTIC_JOB_ARGS} --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1
rc=$?
echo "Finished backup at $(date)" >> /var/log/backup-last.log
logLast "Finished backup at $(date)"
if [[ $rc == 0 ]]; then
echo "Backup Successfull"
else
echo "Backup Failed with Status ${rc}"
restic unlock
copyErrorLog
kill 1
fi
if [ -n "${RESTIC_FORGET_ARGS}" ]; then
echo "Forget about old snapshots based on RESTIC_FORGET_ARGS = ${RESTIC_FORGET_ARGS}"
restic forget ${RESTIC_FORGET_ARGS} >> /var/log/backup-last.log 2>&1
restic forget ${RESTIC_FORGET_ARGS} >> ${lastLogfile} 2>&1
rc=$?
echo "Finished forget at $(date)" >> /var/log/backup-last.log
logLast "Finished forget at $(date)"
if [[ $rc == 0 ]]; then
echo "Forget Successfull"
else
echo "Forget Failed with Status ${rc}"
restic unlock
copyErrorLog
fi
fi
end=`date +%s`
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end-start)) seconds"

View File

@@ -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

3
run.sh
View File

@@ -7,7 +7,8 @@ echo "Start backup-test container. Backup of ~/test-data/ to repository ~/test-r
docker run --privileged --name backup-test \
-e "RESTIC_PASSWORD=test" \
-e "RESTIC_TAG=test" \
-e "BACKUP_CRON=* * * * *" \
-e "BACKUP_CRON=0 0 * * *" \
-e "RESTIC_FORGET_ARGS=--keep-last 10" \
-v ~/test-data:/data \
-v ~/test-repo/:/mnt/restic \
-t restic-backup