mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-04-04 12:18:50 +00:00
Compare commits
21 Commits
1.3.0-TEST
...
1.3.1-0.9.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5596197a6 | ||
|
|
4713b3f13b | ||
|
|
0c8da5f31e | ||
|
|
5a1bec484a | ||
|
|
0f6a7bd462 | ||
|
|
e81386c51a | ||
|
|
11513a9b20 | ||
|
|
9469bbe7ba | ||
|
|
15012cdab1 | ||
|
|
ec42bdd04c | ||
|
|
88620c3acb | ||
|
|
b0408d66a5 | ||
|
|
d10efe97f5 | ||
|
|
29e46cad2c | ||
|
|
0f2df46b9d | ||
|
|
5f5f75f903 | ||
|
|
5c0dbbc9cc | ||
|
|
f4275c5aef | ||
|
|
8a49ee9a53 | ||
|
|
6bedee1ab1 | ||
|
|
5e99ccbc9f |
34
Dockerfile
34
Dockerfile
@@ -1,30 +1,28 @@
|
||||
FROM alpine:3.10.1 as build
|
||||
RUN apk add --no-cache ca-certificates
|
||||
FROM alpine:latest as rclone
|
||||
|
||||
# Get restic executable
|
||||
ENV RESTIC_VERSION=0.9.5
|
||||
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
|
||||
# Get rclone executable
|
||||
ADD https://downloads.rclone.org/rclone-current-linux-amd64.zip /
|
||||
RUN unzip rclone-current-linux-amd64.zip && mv rclone-*-linux-amd64/rclone /bin/rclone && chmod +x /bin/rclone
|
||||
|
||||
FROM alpine:3.10.1
|
||||
FROM restic/restic:0.9.6
|
||||
|
||||
COPY --from=build /etc/ssl/certs /etc/ssl/certs
|
||||
COPY --from=build /bin/restic /bin/restic
|
||||
# install mailx
|
||||
RUN apk add --update --no-cache heirloom-mailx fuse
|
||||
|
||||
RUN apk add --update --no-cache fuse openssh-client
|
||||
COPY --from=rclone /bin/rclone /bin/rclone
|
||||
|
||||
RUN \
|
||||
mkdir -p /mnt/restic /var/spool/cron/crontabs /var/log; \
|
||||
touch /var/log/cron.log;
|
||||
|
||||
ENV \
|
||||
RESTIC_REPOSITORY=/mnt/restic \
|
||||
RESTIC_PASSWORD="" \
|
||||
RESTIC_TAG="" \
|
||||
NFS_TARGET="" \
|
||||
BACKUP_CRON="0 */6 * * *" \
|
||||
RESTIC_FORGET_ARGS="" \
|
||||
RESTIC_JOB_ARGS=""
|
||||
ENV RESTIC_REPOSITORY=/mnt/restic
|
||||
ENV RESTIC_PASSWORD=""
|
||||
ENV RESTIC_TAG=""
|
||||
ENV NFS_TARGET=""
|
||||
ENV BACKUP_CRON="0 */6 * * *"
|
||||
ENV RESTIC_FORGET_ARGS=""
|
||||
ENV RESTIC_JOB_ARGS=""
|
||||
ENV MAILX_ARGS=""
|
||||
|
||||
# /data is the dir where you have to put the data to be backed up
|
||||
VOLUME /data
|
||||
|
||||
11
README.md
11
README.md
@@ -60,7 +60,7 @@ docker logs
|
||||
```
|
||||
Shows `/var/log/cron.log`
|
||||
|
||||
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`.
|
||||
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`. If configured, you can find the full output of the mail notification in `/var/log/mail-last.log`.
|
||||
|
||||
# Customize the Container
|
||||
|
||||
@@ -77,6 +77,7 @@ The container is setup by setting [environment variables](https://docs.docker.co
|
||||
* `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.
|
||||
* `MAILX_ARGS` - Optional. If specified, the content of `/var/log/backup-last.log` is sent via mail after each backup using an *external SMTP*. To have maximum flexibility, you have to specify the mail/smtp parameters by your own. Have a look at the [mailx manpage](https://linux.die.net/man/1/mailx) for further information. Example value: `-e "MAILX_ARGS=-r 'from@example.de' -s 'Result of the last restic backup run' -S smtp='smtp.example.com:587' -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user='username' -S smtp-auth-password='password' 'to@example.com'"`.
|
||||
|
||||
## Volumes
|
||||
|
||||
@@ -86,9 +87,9 @@ The container is setup by setting [environment variables](https://docs.docker.co
|
||||
|
||||
Since restic saves the hostname with each snapshot and the hostname of a docker container is derived from it's id you might want to customize this by setting the hostname of the container to another value.
|
||||
|
||||
Either by setting the [environment variable](https://docs.docker.com/engine/reference/run/#env-environment-variables) `HOSTNAME` or with `--hostname` in the [network settings](https://docs.docker.com/engine/reference/run/#network-settings)
|
||||
Set `--hostname` in the [network settings](https://docs.docker.com/engine/reference/run/#network-settings)
|
||||
|
||||
## Backup to SFTP
|
||||
## Backup via SFTP
|
||||
|
||||
Since restic needs a **password less login** to the SFTP server make sure you can do `sftp user@host` from inside the container. If you can do so from your host system, the easiest way is to just mount your `.ssh` folder conaining the authorized cert into the container by specifying `-v ~/.ssh:/root/.ssh` as argument for `docker run`.
|
||||
|
||||
@@ -98,6 +99,10 @@ Now you can simply specify the restic repository to be an [SFTP repository](http
|
||||
-e "RESTIC_REPOSITORY=sftp:user@host:/tmp/backup"
|
||||
```
|
||||
|
||||
## Backup via rclone
|
||||
|
||||
To use rclone as a backend for restic, simply add the rclone config file as a volume with `-v /absolute/path/to/rclone.conf:/root/.config/rclone/rclone.conf`.
|
||||
|
||||
# Versioning & Changelog
|
||||
|
||||
Starting from v1.3.0 versioning follows [Semantic versioning](http://semver.org/)
|
||||
|
||||
12
backup.sh
12
backup.sh
@@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
lastLogfile="/var/log/backup-last.log"
|
||||
lastMailLogfile="/var/log/mail-last.log"
|
||||
|
||||
copyErrorLog() {
|
||||
cp ${lastLogfile} /var/log/backup-error-last.log
|
||||
@@ -11,7 +12,7 @@ logLast() {
|
||||
}
|
||||
|
||||
start=`date +%s`
|
||||
rm -f ${lastLogfile}
|
||||
rm -f ${lastLogfile} ${lastMailLogfile}
|
||||
echo "Starting Backup at $(date +"%Y-%m-%d %H:%M:%S")"
|
||||
echo "Starting Backup at $(date)" >> ${lastLogfile}
|
||||
logLast "BACKUP_CRON: ${BACKUP_CRON}"
|
||||
@@ -50,3 +51,12 @@ fi
|
||||
|
||||
end=`date +%s`
|
||||
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end-start)) seconds"
|
||||
|
||||
if [ -n "${MAILX_ARGS}" ]; then
|
||||
sh -c "mailx -v -S sendwait ${MAILX_ARGS} < ${lastLogfile} > ${lastMailLogfile} 2>&1"
|
||||
if [ $? == 0 ]; then
|
||||
echo "Mail notification successfully sent."
|
||||
else
|
||||
echo "Sending mail notification FAILED. Check ${lastMailLogfile} for further information."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -18,4 +18,4 @@ fileExistenceTests:
|
||||
metadataTest:
|
||||
volumes: ["/data"]
|
||||
entrypoint: ["/entry.sh"]
|
||||
cmd: ["tail","-fn0", "/var/log/cron.log"]
|
||||
cmd: ["tail","-fn0", "/var/log/cron.log"]
|
||||
@@ -1,9 +1,9 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
test:
|
||||
sut:
|
||||
image: gcr.io/gcp-runtimes/container-structure-test
|
||||
command: ["test", "--image", "restic-backup", "--config", "config.yml"]
|
||||
volumes:
|
||||
- ./config.yml:/config.yml
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
2
run.sh
2
run.sh
@@ -7,7 +7,7 @@ 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=0 0 * * *" \
|
||||
-e "BACKUP_CRON=* * * * *" \
|
||||
-e "RESTIC_FORGET_ARGS=--keep-last 10" \
|
||||
-v ~/test-data:/data \
|
||||
-v ~/test-repo/:/mnt/restic \
|
||||
|
||||
Reference in New Issue
Block a user