mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-04-04 12:18:50 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0cafd0ec9 | ||
|
|
6e8f00b5b3 | ||
|
|
d53bc0a4a5 | ||
|
|
8ba9fb4a8f | ||
|
|
0490f182d5 | ||
|
|
ca25a281d3 |
10
Dockerfile
10
Dockerfile
@@ -1,13 +1,13 @@
|
||||
FROM gliderlabs/alpine:3.3
|
||||
FROM golang:1.7-alpine
|
||||
MAINTAINER info@lobaro.com
|
||||
|
||||
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 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 go
|
||||
RUN apk del git
|
||||
|
||||
RUN mkdir /mnt/restic
|
||||
|
||||
@@ -28,5 +28,9 @@ RUN chmod +x /bin/backup
|
||||
COPY entry.sh /entry.sh
|
||||
|
||||
RUN touch /var/log/cron.log
|
||||
|
||||
WORKDIR "/"
|
||||
|
||||
#ENTRYPOINT ["ls"]
|
||||
ENTRYPOINT ["/entry.sh"]
|
||||
|
||||
|
||||
26
README.md
26
README.md
@@ -9,6 +9,12 @@ 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
|
||||
```
|
||||
@@ -45,14 +51,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
|
||||
|
||||
@@ -65,7 +71,7 @@ The container is setup by setting [environment variables](https://docs.docker.co
|
||||
* `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"`
|
||||
* `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"`
|
||||
|
||||
## Volumes
|
||||
|
||||
@@ -87,6 +93,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
|
||||
|
||||
32
backup.sh
32
backup.sh
@@ -1,27 +1,49 @@
|
||||
#!/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}"
|
||||
|
||||
|
||||
# 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 --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
|
||||
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)) sconds"
|
||||
|
||||
3
run.sh
3
run.sh
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user