3 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
7 changed files with 34 additions and 89 deletions

View File

@@ -1,28 +1,26 @@
FROM alpine:latest as rclone
FROM alpine as certs
RUN apk add --no-cache ca-certificates
# 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 restic/restic:0.9.6
FROM busybox:glibc
# install mailx
RUN apk add --update --no-cache heirloom-mailx fuse
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY --from=rclone /bin/rclone /bin/rclone
# 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; \
touch /var/log/cron.log;
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="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
@@ -30,8 +28,9 @@ VOLUME /data
COPY backup.sh /bin/backup
COPY entry.sh /entry.sh
RUN touch /var/log/cron.log
WORKDIR "/"
ENTRYPOINT ["/entry.sh"]
CMD ["tail","-fn0","/var/log/cron.log"]

View File

@@ -4,19 +4,19 @@ A docker container to automate [restic backups](https://restic.github.io/)
This container runs restic backups in regular intervals.
* Easy setup and maintanance
* Support for different targets (tested with: Local, NFS, SFTP, AWS)
* Support for different targets (currently: Local, NFS, SFTP)
* Support `restic mount` inside the container to browse the backup files
**Container**: [lobaro/restic-backup-docker](https://hub.docker.com/r/lobaro/restic-backup-docker/)
Stable
```
docker pull lobaro/restic-backup-docker:1.2-0.9.4
docker pull lobaro/restic-backup-docker:v1.0
```
Latest (experimental)
```
docker pull lobaro/restic-backup-docker:latest
docker pull lobaro/restic-backup-docker
```
Please don't hesitate to report any issue you find. **Thanks.**
@@ -50,7 +50,7 @@ To enter your container execute
docker exec -ti backup-test /bin/sh
```
Now you can use restic [as documented](https://restic.readthedocs.io/en/stable/), e.g. try to run `restic snapshots` to list all your snapshots.
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 are inside the container. If needed you can create volumes for them.
@@ -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`. If configured, you can find the full output of the mail notification in `/var/log/mail-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`.
# Customize the Container
@@ -77,7 +77,6 @@ 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
@@ -85,11 +84,11 @@ The container is setup by setting [environment variables](https://docs.docker.co
## Set the hostname
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.
Since restic saves the hostname with each snapshot and the hostname of a docker container is it's id you might want to customize this by setting the hostname of the container to another value.
Set `--hostname` in the [network settings](https://docs.docker.com/engine/reference/run/#network-settings)
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)
## Backup via SFTP
## Backup to 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`.
@@ -99,16 +98,16 @@ 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
# Changelog
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 follows [Semantic versioning](http://semver.org/)
# Versioning & Changelog
! Breaking changes
Starting from v1.3.0 versioning follows [Semantic versioning](http://semver.org/)
**: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.
Build metadata is used to declare the Restic version.
**Example:** 1.3.0+0.9.5 (includes Restic 0.9.5)
For changelog see: https://github.com/lobaro/restic-backup-docker/releases
**:v1.0**
* First stable version

View File

@@ -1,7 +1,6 @@
#!/bin/sh
lastLogfile="/var/log/backup-last.log"
lastMailLogfile="/var/log/mail-last.log"
copyErrorLog() {
cp ${lastLogfile} /var/log/backup-error-last.log
@@ -12,7 +11,7 @@ logLast() {
}
start=`date +%s`
rm -f ${lastLogfile} ${lastMailLogfile}
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}"
@@ -51,12 +50,3 @@ 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

View File

@@ -1,21 +0,0 @@
schemaVersion: '2.0.0'
commandTests:
- name: "restic package installation"
setup: [["/entry.sh"]]
command: "which"
args: ["restic"]
expectedOutput: ["/bin/restic"]
fileExistenceTests:
- name: 'log directory exists'
path: '/var/log'
shouldExist: true
- name: 'cron log file exists'
path: '/var/log/cron.log'
shouldExist: true
- name: 'backup script exists'
path: '/bin/backup'
shouldExist: true
metadataTest:
volumes: ["/data"]
entrypoint: ["/entry.sh"]
cmd: ["tail","-fn0", "/var/log/cron.log"]

View File

@@ -1,9 +0,0 @@
version: '2'
services:
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

View File

@@ -1,4 +1,5 @@
#!bin/sh
set -e
echo "Starting container ..."
@@ -13,25 +14,11 @@ if [ -n "${NFS_TARGET}" ]; then
mount -o nolock -v ${NFS_TARGET} /mnt/restic
fi
restic snapshots &>/dev/null
status=$?
echo "Check Repo status $status"
if [ $status != 0 ]; then
if [ ! -f "$RESTIC_REPOSITORY/config" ]; then
echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init."
restic init
init_status=$?
echo "Repo init status $init_status"
if [ $init_status != 0 ]; then
echo "Failed to init the repository: '${RESTIC_REPOSITORY}'"
exit 1
fi
restic init | true
fi
echo "Setup backup cron job with cron expression BACKUP_CRON: ${BACKUP_CRON}"
echo "${BACKUP_CRON} /bin/backup >> /var/log/cron.log 2>&1" > /var/spool/cron/crontabs/root
@@ -43,4 +30,4 @@ crond
echo "Container started."
exec "$@"
tail -fn0 /var/log/cron.log

2
run.sh
View File

@@ -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=* * * * *" \
-e "BACKUP_CRON=0 0 * * *" \
-e "RESTIC_FORGET_ARGS=--keep-last 10" \
-v ~/test-data:/data \
-v ~/test-repo/:/mnt/restic \