From 4cdfc85445626d06481e0312d01f8014baf11b61 Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 10:18:06 +0000 Subject: [PATCH 1/9] added general repository checking --- entry.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/entry.sh b/entry.sh index a01f82d..42ae1d8 100755 --- a/entry.sh +++ b/entry.sh @@ -1,5 +1,4 @@ #!bin/sh -set -e echo "Starting container ..." @@ -14,11 +13,22 @@ if [ -n "${NFS_TARGET}" ]; then mount -o nolock -v ${NFS_TARGET} /mnt/restic fi -if [ ! -f "$RESTIC_REPOSITORY/config" ]; then +restic snapshots &>/dev/null +status=$? +echo "Check Repo status $status" + +if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." restic init | true + + if [ $? == 0 ]; then + echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" + exit 1 + fi 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 @@ -30,4 +40,4 @@ crond echo "Container started." -tail -fn0 /var/log/cron.log +tail -fn0 /var/log/cron.log \ No newline at end of file From 8aa40aa6822ca1f6664d53d6de1e44c23b9114af Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 11:05:34 +0000 Subject: [PATCH 2/9] fixed status check --- entry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry.sh b/entry.sh index 42ae1d8..cfaa7b3 100755 --- a/entry.sh +++ b/entry.sh @@ -21,7 +21,7 @@ if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." restic init | true - if [ $? == 0 ]; then + if [ $? != 0 ]; then echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" exit 1 fi From 1033900afc9707bdf2c398bd5810cdcf1d1bcca0 Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Wed, 19 Jun 2019 21:06:17 +0000 Subject: [PATCH 3/9] corrected check status --- entry.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/entry.sh b/entry.sh index cfaa7b3..42c3ea5 100755 --- a/entry.sh +++ b/entry.sh @@ -19,9 +19,12 @@ echo "Check Repo status $status" if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." - restic init | true + restic init - if [ $? != 0 ]; then + init_status=$? + echo "Repo init status $init_status" + + if [ $init_status != 0 ]; then echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" exit 1 fi From 31a9e3f3282d0044eeb97a4a8ba2358b2858526a Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Sun, 7 Jul 2019 12:44:55 +0100 Subject: [PATCH 4/9] added changes from master --- Dockerfile | 2 +- config.yml | 21 +++++++++++++++++++++ docker-compose.test.yml | 9 +++++++++ entry.sh | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 config.yml create mode 100644 docker-compose.test.yml diff --git a/Dockerfile b/Dockerfile index e3c3742..f64f3ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,4 @@ RUN touch /var/log/cron.log WORKDIR "/" ENTRYPOINT ["/entry.sh"] - +CMD ["tail","-fn0","/var/log/cron.log"] \ No newline at end of file diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..12228f0 --- /dev/null +++ b/config.yml @@ -0,0 +1,21 @@ +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"] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..364a7b6 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,9 @@ +version: '2' + +services: + test: + 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 \ No newline at end of file diff --git a/entry.sh b/entry.sh index 42c3ea5..38fb703 100755 --- a/entry.sh +++ b/entry.sh @@ -43,4 +43,4 @@ crond echo "Container started." -tail -fn0 /var/log/cron.log \ No newline at end of file +exec "$@" \ No newline at end of file From b4ed623bd4d5969fddcee752a71cdfdc2172844e Mon Sep 17 00:00:00 2001 From: crast Date: Sun, 23 Jun 2019 13:58:17 -0600 Subject: [PATCH 5/9] Reduce layer count in Docker image: * move the bzip2 and extraction into the scratch image * combine commands and ENV directives to make less layers --- Dockerfile | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index f64f3ed..356421e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,28 @@ FROM alpine as certs RUN apk add --no-cache ca-certificates - -FROM busybox:glibc - -COPY --from=certs /etc/ssl/certs /etc/ssl/certs - # 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 -RUN mkdir -p /mnt/restic /var/spool/cron/crontabs /var/log +FROM busybox:glibc -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="" +COPY --from=certs /etc/ssl/certs /etc/ssl/certs +COPY --from=certs /bin/restic /bin/restic + +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="" # /data is the dir where you have to put the data to be backed up VOLUME /data @@ -28,7 +30,6 @@ VOLUME /data COPY backup.sh /bin/backup COPY entry.sh /entry.sh -RUN touch /var/log/cron.log WORKDIR "/" From 71feaad5b40cf67e53b70b20965083b080aa0230 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Fri, 19 Jul 2019 00:12:44 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1eb2e1b..586b13c 100644 --- a/README.md +++ b/README.md @@ -98,16 +98,12 @@ Now you can simply specify the restic repository to be an [SFTP repository](http -e "RESTIC_REPOSITORY=sftp:user@host:/tmp/backup" ``` -# Changelog +# Versioning & Changelog -Versioning follows [Semantic versioning](http://semver.org/) +Starting from v1.3.0 versioning follows [Semantic versioning](http://semver.org/) -! Breaking changes +Build metadata is used to declare the Restic version. -**: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. +**Example:** 1.3.0+0.9.5 (includes Restic 0.9.5) - -**:v1.0** -* First stable version +For Changelog see: https://github.com/lobaro/restic-backup-docker/releases From 6613cd39b3c9cbc402c46061b12b6cfdd0496fba Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Fri, 19 Jul 2019 00:13:09 +0200 Subject: [PATCH 7/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 586b13c..55f2eba 100644 --- a/README.md +++ b/README.md @@ -106,4 +106,4 @@ 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 +For changelog see: https://github.com/lobaro/restic-backup-docker/releases From f99b15304f7f7c20e51b9e0b23fd2696a20e93bb Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Fri, 19 Jul 2019 00:18:20 +0200 Subject: [PATCH 8/9] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55f2eba..6421f39 100644 --- a/README.md +++ b/README.md @@ -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 (currently: Local, NFS, SFTP) +* Support for different targets (tested with: Local, NFS, SFTP, AWS) * 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:v1.0 +docker pull lobaro/restic-backup-docker:v1.2 ``` Latest (experimental) ``` -docker pull lobaro/restic-backup-docker +docker pull lobaro/restic-backup-docker:latest ``` 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/Manual/), 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/), 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. @@ -84,7 +84,7 @@ 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 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 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) From 683db322d7de652d7c727139a577bde5352cb382 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Fri, 19 Jul 2019 00:19:55 +0200 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6421f39..cf0723d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This container runs restic backups in regular intervals. Stable ``` -docker pull lobaro/restic-backup-docker:v1.2 +docker pull lobaro/restic-backup-docker:1.2-0.9.4 ``` Latest (experimental)