From 793cba03f5ef27a239b4e8d26adf663132625773 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Mon, 3 Feb 2020 11:50:07 -0500 Subject: [PATCH 1/6] Include the Restic binary in the image. --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index ef2ebaa..974fa56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,14 @@ RUN wget https://raw.githubusercontent.com/silinternational/runny/0.2/runny \ -O /usr/local/bin/runny \ && chmod +x /usr/local/bin/runny +ARG restic_ver=0.9.6 + +RUN wget https://github.com/restic/restic/releases/download/v${restic_ver}/restic_${restic_ver}_linux_amd64.bz2 \ + -O /tmp/restic.bz2 \ + && bunzip2 /tmp/restic.bz2 \ + && chmod +x /tmp/restic \ + && mv /tmp/restic /usr/local/bin/restic + COPY application/ /data/ WORKDIR /data From 0eedb602baa9f0a1e25a3823ebfe27374b8838a0 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Mon, 3 Feb 2020 14:31:43 -0500 Subject: [PATCH 2/6] Remove extra shell invocation. --- application/backup.sh | 6 +++--- application/init.sh | 2 +- application/restore.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/backup.sh b/application/backup.sh index 325faa1..d47f05e 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -3,19 +3,19 @@ logger -p user.info "Started backup..." start=$(date +%s) -runny $(/usr/local/bin/restic backup ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH}) +runny /usr/local/bin/restic backup ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} end=$(date +%s) logger -p user.info "Backup completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny $(/usr/local/bin/restic forget ${RESTIC_FORGET_ARGS} --prune) +runny /usr/local/bin/restic forget ${RESTIC_FORGET_ARGS} --prune end=$(date +%s) logger -p user.info "Backup pruning completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny $(/usr/local/bin/restic check) +runny /usr/local/bin/restic check end=$(date +%s) logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." diff --git a/application/init.sh b/application/init.sh index af99a37..fd5554e 100755 --- a/application/init.sh +++ b/application/init.sh @@ -3,7 +3,7 @@ logger -p user.info "Started Restic repository initialization..." start=$(date +%s) -runny $(/usr/local/bin/restic init) +runny /usr/local/bin/restic init end=$(date +%s) logger -p user.info "Repository initialization completed in $(expr ${end} - ${start}) seconds." diff --git a/application/restore.sh b/application/restore.sh index 319f75b..c312b84 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -3,7 +3,7 @@ logger -p user.info "Restoring ${RESTIC_RESTORE_ID}..." start=$(date +%s) -runny $(/usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --target ${TARGET_PATH}) +runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --target ${TARGET_PATH} end=$(date +%s) logger -p user.info "Restoration completed in $(expr ${end} - ${start}) seconds." From af2eea26dff9521e28982925741de40ea3496d33 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 4 Feb 2020 10:45:29 -0500 Subject: [PATCH 3/6] Add tagging to allow restore of "latest" snapshot. --- README.md | 6 +++--- application/backup.sh | 2 +- application/entrypoint.sh | 2 -- application/restore.sh | 2 +- local.env.dist | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a3acab8..c480295 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ Docker image to initialize, backup to, and restore from a Restic repository on A 8. `RESTIC_FORGET_ARGS` - additional arguments to pass to 'restic forget --prune' command (e.g., --keep-daily 7 --keep-weekly 5 --keep-monthly 3 --keep-yearly 2) -9. `RESTIC_HOST` - hostname to record as source of backup +9. `RESTIC_PASSWORD` - password for the Restic repository -10. `RESTIC_PASSWORD` - password for the Restic repository +10. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') -11. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') +11. `RESTIC_TAG` - tag to apply to the backup 12. `SOURCE_PATH` - full path to the source directory to be backed up diff --git a/application/backup.sh b/application/backup.sh index d47f05e..710b777 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -3,7 +3,7 @@ logger -p user.info "Started backup..." start=$(date +%s) -runny /usr/local/bin/restic backup ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} +runny /usr/local/bin/restic backup --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} end=$(date +%s) logger -p user.info "Backup completed in $(expr ${end} - ${start}) seconds." diff --git a/application/entrypoint.sh b/application/entrypoint.sh index 0afd7ec..015439d 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -1,7 +1,5 @@ #!/usr/bin/env sh -hostname ${RESTIC_HOST} - if [ "${LOGENTRIES_KEY}" ]; then sed -i /etc/rsyslog.conf -e "s/LOGENTRIESKEY/${LOGENTRIES_KEY}/" rsyslogd diff --git a/application/restore.sh b/application/restore.sh index c312b84..46d032d 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -3,7 +3,7 @@ logger -p user.info "Restoring ${RESTIC_RESTORE_ID}..." start=$(date +%s) -runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --target ${TARGET_PATH} +runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --tag ${RESTIC_TAG} --target ${TARGET_PATH} end=$(date +%s) logger -p user.info "Restoration completed in $(expr ${end} - ${start}) seconds." diff --git a/local.env.dist b/local.env.dist index 2a2b9f0..0cb2843 100644 --- a/local.env.dist +++ b/local.env.dist @@ -6,8 +6,8 @@ FSBACKUP_MODE= LOGENTRIES_KEY= RESTIC_BACKUP_ARGS= RESTIC_FORGET_ARGS= -RESTIC_HOST= RESTIC_PASSWORD= RESTIC_REPOSITORY= +RESTIC_TAG= SOURCE_PATH= TARGET_PATH= From d4dd027415e677eaac836a19545f391792937ab9 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 4 Feb 2020 13:08:41 -0500 Subject: [PATCH 4/6] Specify hostname Restic is to use. --- README.md | 12 +++++++----- application/backup.sh | 4 ++-- application/restore.sh | 2 +- local.env.dist | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c480295..ae5c710 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,17 @@ Docker image to initialize, backup to, and restore from a Restic repository on A 8. `RESTIC_FORGET_ARGS` - additional arguments to pass to 'restic forget --prune' command (e.g., --keep-daily 7 --keep-weekly 5 --keep-monthly 3 --keep-yearly 2) -9. `RESTIC_PASSWORD` - password for the Restic repository +9. `RESTIC_HOST` - hostname to be used for the backup -10. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') +10. `RESTIC_PASSWORD` - password for the Restic repository -11. `RESTIC_TAG` - tag to apply to the backup +11. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') -12. `SOURCE_PATH` - full path to the source directory to be backed up +12. `RESTIC_TAG` - tag to apply to the backup -13. `TARGET_PATH` - full path to the target directory to be restored to (usually the same as the SOURCE\_PATH) +13. `SOURCE_PATH` - full path to the source directory to be backed up + +14. `TARGET_PATH` - full path to the target directory to be restored to (usually the same as the SOURCE\_PATH) It's recommended that your S3 bucket **NOT** have versioning turned on. Old versions of Restic's repository files are not useful. diff --git a/application/backup.sh b/application/backup.sh index 710b777..5a93884 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -3,13 +3,13 @@ logger -p user.info "Started backup..." start=$(date +%s) -runny /usr/local/bin/restic backup --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} +runny /usr/local/bin/restic backup --host ${RESTIC_HOST} --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} end=$(date +%s) logger -p user.info "Backup completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny /usr/local/bin/restic forget ${RESTIC_FORGET_ARGS} --prune +runny /usr/local/bin/restic forget --host ${RESTIC_HOST} ${RESTIC_FORGET_ARGS} --prune end=$(date +%s) logger -p user.info "Backup pruning completed in $(expr ${end} - ${start}) seconds." diff --git a/application/restore.sh b/application/restore.sh index 46d032d..c2ecd33 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -3,7 +3,7 @@ logger -p user.info "Restoring ${RESTIC_RESTORE_ID}..." start=$(date +%s) -runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --tag ${RESTIC_TAG} --target ${TARGET_PATH} +runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --host ${RESTIC_HOST} --tag ${RESTIC_TAG} --target ${TARGET_PATH} end=$(date +%s) logger -p user.info "Restoration completed in $(expr ${end} - ${start}) seconds." diff --git a/local.env.dist b/local.env.dist index 0cb2843..7a7a659 100644 --- a/local.env.dist +++ b/local.env.dist @@ -6,6 +6,7 @@ FSBACKUP_MODE= LOGENTRIES_KEY= RESTIC_BACKUP_ARGS= RESTIC_FORGET_ARGS= +RESTIC_HOST= RESTIC_PASSWORD= RESTIC_REPOSITORY= RESTIC_TAG= From 2f732bf771845c0c75b06d89ced9eb0587259fad Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 4 Feb 2020 15:05:19 -0500 Subject: [PATCH 5/6] Force repository unlock after backup and restore. --- application/backup.sh | 6 ++++++ application/restore.sh | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/application/backup.sh b/application/backup.sh index 5a93884..1c78560 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -20,4 +20,10 @@ end=$(date +%s) logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." +start=$(date +%s) +runny /usr/local/bin/restic unlock +end=$(date +%s) + +logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." + logger -p user.info "...completed backup." diff --git a/application/restore.sh b/application/restore.sh index c2ecd33..49e5673 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -7,3 +7,11 @@ runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --host ${RESTIC_HOST} - end=$(date +%s) logger -p user.info "Restoration completed in $(expr ${end} - ${start}) seconds." + +start=$(date +%s) +runny /usr/local/bin/restic unlock +end=$(date +%s) + +logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." + +logger -p user.info "...completed restore." From b5d4f047854ccfb3d0ff2057b48354b75dba638d Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Fri, 7 Feb 2020 13:55:51 -0500 Subject: [PATCH 6/6] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae5c710..cf9a9b7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Docker image to initialize, backup to, and restore from a Restic repository on A 4. `CRON_SCHEDULE="0 2 * * *"` - Schedule for cron job, _defaults to every day at 2:00 AM_ [syntax reference](https://en.wikipedia.org/wiki/Cron) -5. `FSBACKUP_MODE=[init|backup|restore]` - +5. `FSBACKUP_MODE=[init|backup|restore]` - `init` initializes the Restic repository at `$RESTIC_REPOSITORY` (only do this once); `backup` performs a backup; `restore` performs a restoration. 6. `LOGENTRIES_KEY` - (optional) If provided, the image will send command output to syslog with priority `user.info`.