From 5e99ccbc9f80c384204d5bbe782e25a35077707c Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 10:18:06 +0000 Subject: [PATCH 1/6] 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 6bedee1ab1bbf44c2702afffeaeb27d94eabd5b6 Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 11:05:34 +0000 Subject: [PATCH 2/6] 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 8a49ee9a53d1a2e1b0386498f890f3f52f596ab1 Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Wed, 19 Jun 2019 21:06:17 +0000 Subject: [PATCH 3/6] 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 f4275c5aef2e7d10399b6bf28a39a467890a454b Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Sun, 7 Jul 2019 12:44:55 +0100 Subject: [PATCH 4/6] 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 5f5f75f9030c3915d5ba7bfac246d31757523171 Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Fri, 19 Jul 2019 10:13:21 +0000 Subject: [PATCH 5/6] Fixed dockerhub test --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 364a7b6..61ac2c3 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,7 +1,7 @@ version: '2' services: - test: + sut: image: gcr.io/gcp-runtimes/container-structure-test command: ["test", "--image", "restic-backup", "--config", "config.yml"] volumes: From b0408d66a5ab734ab13e1eb752fccb96b3838898 Mon Sep 17 00:00:00 2001 From: Bruno Inec Date: Mon, 16 Sep 2019 02:43:29 +0200 Subject: [PATCH 6/6] Add rclone to Dockerfile --- Dockerfile | 7 +++++++ README.md | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 356421e..d5cf7fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,17 @@ 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 +FROM alpine as rclone + +# 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 busybox:glibc COPY --from=certs /etc/ssl/certs /etc/ssl/certs COPY --from=certs /bin/restic /bin/restic +COPY --from=rclone /bin/rclone /bin/rclone RUN \ mkdir -p /mnt/restic /var/spool/cron/crontabs /var/log; \ diff --git a/README.md b/README.md index cf0723d..e41c622 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Since restic saves the hostname with each snapshot and the hostname of a docker 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 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 +98,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/)