From 1bfd979bb0eabe99dd297ba9f87185c96ed6c952 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 25 Feb 2020 13:40:28 -0500 Subject: [PATCH 01/10] Send messages to /dev/console. --- dockerbuild/rsyslog.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dockerbuild/rsyslog.conf b/dockerbuild/rsyslog.conf index 2a2b661..d886bcb 100644 --- a/dockerbuild/rsyslog.conf +++ b/dockerbuild/rsyslog.conf @@ -14,3 +14,7 @@ $ActionSendStreamDriverPermittedPeer *.logentries.com $template LogentriesFormat,"LOGENTRIESKEY %msg%\n" *.emerg,*.alert,*.crit,*.err,*.warning,user.* @@data.logentries.com:443;LogentriesFormat + +# Also send messages to the console where they will get logged by +# AWS CloudWatch Logs. +*.emerg,*.alert,*.crit,*.err,*.warning,user.* /dev/console From 108b1533fe3dad076d4ba0fc7a48f1150a26e6d2 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 25 Feb 2020 15:05:12 -0500 Subject: [PATCH 02/10] Use echo to print messages. --- application/backup.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/application/backup.sh b/application/backup.sh index 1c78560..652214c 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -1,29 +1,35 @@ #!/usr/bin/env sh logger -p user.info "Started backup..." +echo "restic-backup-restore: backup: Started" start=$(date +%s) 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." +echo "restic-backup-restore: Backup completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) 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." +echo "restic-backup-restore: Backup pruning completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) runny /usr/local/bin/restic check end=$(date +%s) logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." +echo "restic-backup-restore: 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." +echo "restic-backup-restore: Repository unlock completed in $(expr ${end} - ${start}) seconds." logger -p user.info "...completed backup." +echo "restic-backup-restore: backup: Completed" From 221e0df3ffb1928b9320421957adbfafd0b1f0ca Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 26 Feb 2020 09:46:32 -0500 Subject: [PATCH 03/10] Partially remove runny. --- application/backup.sh | 8 ++++---- application/entrypoint.sh | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/application/backup.sh b/application/backup.sh index 652214c..e4fa882 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -4,28 +4,28 @@ logger -p user.info "Started backup..." echo "restic-backup-restore: backup: Started" start=$(date +%s) -runny /usr/local/bin/restic backup --host ${RESTIC_HOST} --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} +/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." echo "restic-backup-restore: Backup completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny /usr/local/bin/restic forget --host ${RESTIC_HOST} ${RESTIC_FORGET_ARGS} --prune +/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." echo "restic-backup-restore: Backup pruning completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny /usr/local/bin/restic check +/usr/local/bin/restic check end=$(date +%s) logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." echo "restic-backup-restore: Repository check completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) -runny /usr/local/bin/restic unlock +/usr/local/bin/restic unlock end=$(date +%s) logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." diff --git a/application/entrypoint.sh b/application/entrypoint.sh index 015439d..5671938 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -11,4 +11,10 @@ fi # default to every day at 2 am when no schedule is provided echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root -runny $1 +#dkn runny $1 +output=$("$1" 2>&1) +rc=$? +message="$1: exited, Status: ${rc}, Output: ${output}" +logger -p 1 -t application.warn "${message}" +echo "${message}" +exit ${rc} From 99d023365470e9b89dfc2558eab9cc613b0ae636 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 26 Feb 2020 11:08:45 -0500 Subject: [PATCH 04/10] Removed quotes around command to be run. --- application/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/entrypoint.sh b/application/entrypoint.sh index 5671938..fd2145b 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -12,7 +12,7 @@ fi echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root #dkn runny $1 -output=$("$1" 2>&1) +output=$($1 2>&1) rc=$? message="$1: exited, Status: ${rc}, Output: ${output}" logger -p 1 -t application.warn "${message}" From bf2ac0cf8951bb0e2e61e7fa27c872f9e995d3d9 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 26 Feb 2020 13:38:52 -0500 Subject: [PATCH 05/10] Remove another instance of runny. --- application/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/entrypoint.sh b/application/entrypoint.sh index fd2145b..aaa7e59 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -9,7 +9,8 @@ else fi # default to every day at 2 am when no schedule is provided -echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root +#dkn echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root +echo "${CRON_SCHEDULE:=0 2 * * *} /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root #dkn runny $1 output=$($1 2>&1) From 47d6878a524b936cad5643ea2ce16fa5a358c3e5 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 3 Mar 2020 15:27:38 -0500 Subject: [PATCH 06/10] Remove rsyslog and cron; messages to stdout --- Dockerfile | 2 +- application/backup.sh | 12 ++++++------ application/entrypoint.sh | 31 +++++++++++++++++-------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 974fa56..1ad36c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,4 @@ COPY application/ /data/ WORKDIR /data ENTRYPOINT ["./entrypoint.sh"] -CMD ["crond -f"] +#dkn CMD ["crond -f"] diff --git a/application/backup.sh b/application/backup.sh index e4fa882..9f8a74a 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -1,35 +1,35 @@ #!/usr/bin/env sh -logger -p user.info "Started backup..." +#dkn logger -p user.info "Started backup..." echo "restic-backup-restore: backup: Started" start=$(date +%s) /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." +#dkn logger -p user.info "Backup completed in $(expr ${end} - ${start}) seconds." echo "restic-backup-restore: Backup completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) /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." +#dkn logger -p user.info "Backup pruning completed in $(expr ${end} - ${start}) seconds." echo "restic-backup-restore: Backup pruning completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) /usr/local/bin/restic check end=$(date +%s) -logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." +#dkn logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." echo "restic-backup-restore: Repository check completed in $(expr ${end} - ${start}) seconds." start=$(date +%s) /usr/local/bin/restic unlock end=$(date +%s) -logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." +#dkn logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." echo "restic-backup-restore: Repository unlock completed in $(expr ${end} - ${start}) seconds." -logger -p user.info "...completed backup." +#dkn logger -p user.info "...completed backup." echo "restic-backup-restore: backup: Completed" diff --git a/application/entrypoint.sh b/application/entrypoint.sh index aaa7e59..9702e28 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -1,21 +1,24 @@ #!/usr/bin/env sh -if [ "${LOGENTRIES_KEY}" ]; then - sed -i /etc/rsyslog.conf -e "s/LOGENTRIESKEY/${LOGENTRIES_KEY}/" - rsyslogd - sleep 10 # ensure rsyslogd is running before we may need to send logs to it -else - logger -p user.error "Missing LOGENTRIES_KEY environment variable" -fi +#if [ "${LOGENTRIES_KEY}" ]; then +# sed -i /etc/rsyslog.conf -e "s/LOGENTRIESKEY/${LOGENTRIES_KEY}/" +# rsyslogd +# sleep 10 # ensure rsyslogd is running before we may need to send logs to it +#else +# logger -p user.error "Missing LOGENTRIES_KEY environment variable" +#fi # default to every day at 2 am when no schedule is provided #dkn echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root -echo "${CRON_SCHEDULE:=0 2 * * *} /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root +#echo "${CRON_SCHEDULE:=0 2 * * *} /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root #dkn runny $1 -output=$($1 2>&1) -rc=$? -message="$1: exited, Status: ${rc}, Output: ${output}" -logger -p 1 -t application.warn "${message}" -echo "${message}" -exit ${rc} +#output=$($1 2>&1) +#rc=$? +#message="$1: exited, Status: ${rc}, Output: ${output}" +#logger -p 1 -t application.warn "${message}" +#echo "${message}" +#exit ${rc} + +# No environment variable validation or error checking seems dangerous! +/data/${FSBACKUP_MODE}.sh From 743f5afd9c8ecf7d5afda0f37ab01300963c44ed Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 4 Mar 2020 09:52:09 -0500 Subject: [PATCH 07/10] Replace rsyslog/Logentries with output to stdout Removed integration with Logentries and send all output to STDOUT via echo statements. Added status checking. Updated message text. --- Dockerfile | 13 +---------- README.md | 24 +++++++++------------ application/backup.sh | 45 +++++++++++++++++++++++++++------------ application/entrypoint.sh | 32 +++++++++++----------------- application/init.sh | 16 ++++++++++---- application/restore.sh | 26 ++++++++++++++++------ dockerbuild/rsyslog.conf | 20 ----------------- local.env.dist | 2 -- 8 files changed, 87 insertions(+), 91 deletions(-) delete mode 100644 dockerbuild/rsyslog.conf diff --git a/Dockerfile b/Dockerfile index 1ad36c3..ea463e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,7 @@ FROM alpine:3.11 RUN apk update \ - && apk add --no-cache \ - rsyslog rsyslog-tls \ - ca-certificates openssl \ - bash \ - && update-ca-certificates - -COPY dockerbuild/rsyslog.conf /etc/rsyslog.conf - -RUN wget https://raw.githubusercontent.com/silinternational/runny/0.2/runny \ - -O /usr/local/bin/runny \ - && chmod +x /usr/local/bin/runny + && apk add --no-cache bash ARG restic_ver=0.9.6 @@ -25,4 +15,3 @@ COPY application/ /data/ WORKDIR /data ENTRYPOINT ["./entrypoint.sh"] -#dkn CMD ["crond -f"] diff --git a/README.md b/README.md index cf9a9b7..81beb15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# docker-restic-backup +# restic-backup-restore Docker image to initialize, backup to, and restore from a Restic repository on AWS S3. ## How to use it @@ -14,27 +14,23 @@ Docker image to initialize, backup to, and restore from a Restic repository on A 3. `AWS_DEFAULT_REGION` - AWS default region for S3 bucket -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) +4. `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. -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. +5. `RESTIC_BACKUP_ARGS` - additional arguments to pass to 'restic backup' command -6. `LOGENTRIES_KEY` - (optional) If provided, the image will send command output to syslog with priority `user.info`. +6. `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) -7. `RESTIC_BACKUP_ARGS` - additional arguments to pass to 'restic backup' command +7. `RESTIC_HOST` - hostname to be used for the backup -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) +8. `RESTIC_PASSWORD` - password for the Restic repository -9. `RESTIC_HOST` - hostname to be used for the backup +9. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') -10. `RESTIC_PASSWORD` - password for the Restic repository +10. `RESTIC_TAG` - tag to apply to the backup -11. `RESTIC_REPOSITORY` - Restic repository location (e.g., 's3:s3.amazonaws.com/bucketname/restic') +11. `SOURCE_PATH` - full path to the source directory to be backed up -12. `RESTIC_TAG` - tag to apply to the backup - -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) +12. `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 9f8a74a..eb047e7 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -1,35 +1,52 @@ #!/usr/bin/env sh -#dkn logger -p user.info "Started backup..." +STATUS=0 + echo "restic-backup-restore: backup: Started" start=$(date +%s) -/usr/local/bin/restic backup --host ${RESTIC_HOST} --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} +/usr/local/bin/restic backup --host ${RESTIC_HOST} --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} || STATUS=$? end=$(date +%s) -#dkn logger -p user.info "Backup completed in $(expr ${end} - ${start}) seconds." -echo "restic-backup-restore: Backup completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Backup returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Backup completed in $(expr ${end} - ${start}) seconds." +fi start=$(date +%s) -/usr/local/bin/restic forget --host ${RESTIC_HOST} ${RESTIC_FORGET_ARGS} --prune +/usr/local/bin/restic forget --host ${RESTIC_HOST} ${RESTIC_FORGET_ARGS} --prune || STATUS=$? end=$(date +%s) -#dkn logger -p user.info "Backup pruning completed in $(expr ${end} - ${start}) seconds." -echo "restic-backup-restore: Backup pruning completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Backup pruning returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Backup pruning completed in $(expr ${end} - ${start}) seconds." +fi start=$(date +%s) -/usr/local/bin/restic check +/usr/local/bin/restic check || STATUS=$? end=$(date +%s) -#dkn logger -p user.info "Repository check completed in $(expr ${end} - ${start}) seconds." -echo "restic-backup-restore: Repository check completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Repository check returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Repository check completed in $(expr ${end} - ${start}) seconds." +fi start=$(date +%s) -/usr/local/bin/restic unlock +/usr/local/bin/restic unlock || STATUS=$? end=$(date +%s) -#dkn logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." -echo "restic-backup-restore: Repository unlock completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Repository unlock returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Repository unlock completed in $(expr ${end} - ${start}) seconds." +fi -#dkn logger -p user.info "...completed backup." echo "restic-backup-restore: backup: Completed" +exit $STATUS diff --git a/application/entrypoint.sh b/application/entrypoint.sh index 9702e28..2324b38 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -1,24 +1,18 @@ #!/usr/bin/env sh -#if [ "${LOGENTRIES_KEY}" ]; then -# sed -i /etc/rsyslog.conf -e "s/LOGENTRIESKEY/${LOGENTRIES_KEY}/" -# rsyslogd -# sleep 10 # ensure rsyslogd is running before we may need to send logs to it -#else -# logger -p user.error "Missing LOGENTRIES_KEY environment variable" -#fi +STATUS=0 -# default to every day at 2 am when no schedule is provided -#dkn echo "${CRON_SCHEDULE:=0 2 * * *} runny /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root -#echo "${CRON_SCHEDULE:=0 2 * * *} /data/${FSBACKUP_MODE}.sh" >> /etc/crontabs/root +case "${FSBACKUP_MODE}" in + INIT|BACKUP|RESTORE) + /data/${FSBACKUP_MODE}.sh || STATUS=$? + ;; + *) + echo restic-backup-restore: FATAL: Unknown FSBACKUP_MODE: ${FSBACKUP_MODE} + exit 1 +esac -#dkn runny $1 -#output=$($1 2>&1) -#rc=$? -#message="$1: exited, Status: ${rc}, Output: ${output}" -#logger -p 1 -t application.warn "${message}" -#echo "${message}" -#exit ${rc} +if [ $STATUS -ne 0 ]; then + echo restic-backup-restore: Non-zero exit: $STATUS +fi -# No environment variable validation or error checking seems dangerous! -/data/${FSBACKUP_MODE}.sh +exit $STATUS diff --git a/application/init.sh b/application/init.sh index fd5554e..0735631 100755 --- a/application/init.sh +++ b/application/init.sh @@ -1,11 +1,19 @@ #!/usr/bin/env sh -logger -p user.info "Started Restic repository initialization..." +STATUS=0 + +echo "restic-backup-restore: init: Started" start=$(date +%s) -runny /usr/local/bin/restic init +/usr/local/bin/restic init || STATUS=$? end=$(date +%s) -logger -p user.info "Repository initialization completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Repository initialization returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Repository initialization completed in $(expr ${end} - ${start}) seconds. +fi -logger -p user.info "...completed repository initialization." +echo "restic-backup-restore: init: Completed" +exit $STATUS diff --git a/application/restore.sh b/application/restore.sh index 49e5673..a46f192 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -1,17 +1,31 @@ #!/usr/bin/env sh -logger -p user.info "Restoring ${RESTIC_RESTORE_ID}..." +STATUS=0 + +echo "restic-backup-restore: restore: Started" +echo "restic-backup-restore: Restoring ${RESTIC_RESTORE_ID}" start=$(date +%s) -runny /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --host ${RESTIC_HOST} --tag ${RESTIC_TAG} --target ${TARGET_PATH} +/usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --host ${RESTIC_HOST} --tag ${RESTIC_TAG} --target ${TARGET_PATH} || STATUS=$? end=$(date +%s) -logger -p user.info "Restoration completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Restore returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Restore completed in $(expr ${end} - ${start}) seconds." +fi start=$(date +%s) -runny /usr/local/bin/restic unlock +/usr/local/bin/restic unlock || STATUS=$? end=$(date +%s) -logger -p user.info "Repository unlock completed in $(expr ${end} - ${start}) seconds." +if [ $STATUS -ne 0 ]; then + echo "restic-backup-restore: FATAL: Repository unlock returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." + exit $STATUS +else + echo "restic-backup-restore: Repository unlock completed in $(expr ${end} - ${start}) seconds." +fi -logger -p user.info "...completed restore." +echo "restic-backup-restore: restore: Completed" +exit $STATUS diff --git a/dockerbuild/rsyslog.conf b/dockerbuild/rsyslog.conf deleted file mode 100644 index d886bcb..0000000 --- a/dockerbuild/rsyslog.conf +++ /dev/null @@ -1,20 +0,0 @@ -# if you experience problems, check: -# http://www.rsyslog.com/troubleshoot - -$ModLoad imuxsock # provides support for local system logging (e.g. via logger command) - -# -# Configure TLS (logentries-specific example: https://docs.logentries.com/docs/rsyslog/) -# -$DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-certificates.crt -$ActionSendStreamDriver gtls -$ActionSendStreamDriverMode 1 -$ActionSendStreamDriverAuthMode x509/name -$ActionSendStreamDriverPermittedPeer *.logentries.com - -$template LogentriesFormat,"LOGENTRIESKEY %msg%\n" -*.emerg,*.alert,*.crit,*.err,*.warning,user.* @@data.logentries.com:443;LogentriesFormat - -# Also send messages to the console where they will get logged by -# AWS CloudWatch Logs. -*.emerg,*.alert,*.crit,*.err,*.warning,user.* /dev/console diff --git a/local.env.dist b/local.env.dist index 7a7a659..c3624d7 100644 --- a/local.env.dist +++ b/local.env.dist @@ -1,9 +1,7 @@ AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION= -CRON_SCHEDULE= FSBACKUP_MODE= -LOGENTRIES_KEY= RESTIC_BACKUP_ARGS= RESTIC_FORGET_ARGS= RESTIC_HOST= From e6d804b856ec89ce9be1b6c2e217c7177d02e0cf Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 4 Mar 2020 10:09:10 -0500 Subject: [PATCH 08/10] Fix typos --- application/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/entrypoint.sh b/application/entrypoint.sh index 2324b38..9df46db 100755 --- a/application/entrypoint.sh +++ b/application/entrypoint.sh @@ -3,7 +3,7 @@ STATUS=0 case "${FSBACKUP_MODE}" in - INIT|BACKUP|RESTORE) + init|backup|restore) /data/${FSBACKUP_MODE}.sh || STATUS=$? ;; *) From f12484c97104289cfd7667e51f5bdd341cec0d84 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Wed, 4 Mar 2020 15:08:01 -0500 Subject: [PATCH 09/10] Replace ENTRYPOINT with CMD. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ea463e7..57aa1ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,5 @@ RUN wget https://github.com/restic/restic/releases/download/v${restic_ver}/resti COPY application/ /data/ WORKDIR /data -ENTRYPOINT ["./entrypoint.sh"] +#dkn ENTRYPOINT ["./entrypoint.sh"] +CMD ["./entrypoint.sh"] From e4ad440143acd918a0ab1e3387cb06b85b3788f6 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Tue, 10 Mar 2020 14:20:18 -0400 Subject: [PATCH 10/10] Code cleanup --- Dockerfile | 5 ++--- application/backup.sh | 1 + application/restore.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 57aa1ea..7bf6ec2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,8 @@ RUN apk update \ 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 \ +RUN wget -O /tmp/restic.bz2 \ + https://github.com/restic/restic/releases/download/v${restic_ver}/restic_${restic_ver}_linux_amd64.bz2 \ && bunzip2 /tmp/restic.bz2 \ && chmod +x /tmp/restic \ && mv /tmp/restic /usr/local/bin/restic @@ -14,5 +14,4 @@ RUN wget https://github.com/restic/restic/releases/download/v${restic_ver}/resti COPY application/ /data/ WORKDIR /data -#dkn ENTRYPOINT ["./entrypoint.sh"] CMD ["./entrypoint.sh"] diff --git a/application/backup.sh b/application/backup.sh index eb047e7..68cf5f6 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -3,6 +3,7 @@ STATUS=0 echo "restic-backup-restore: backup: Started" +echo "restic-backup-restore: Backing up ${SOURCE_PATH}" start=$(date +%s) /usr/local/bin/restic backup --host ${RESTIC_HOST} --tag ${RESTIC_TAG} ${RESTIC_BACKUP_ARGS} ${SOURCE_PATH} || STATUS=$? diff --git a/application/restore.sh b/application/restore.sh index a46f192..73835c6 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -3,7 +3,7 @@ STATUS=0 echo "restic-backup-restore: restore: Started" -echo "restic-backup-restore: Restoring ${RESTIC_RESTORE_ID}" +echo "restic-backup-restore: Restoring ${RESTIC_RESTORE_ID} to ${TARGET_PATH}" start=$(date +%s) /usr/local/bin/restic restore ${RESTIC_RESTORE_ID} --host ${RESTIC_HOST} --tag ${RESTIC_TAG} --target ${TARGET_PATH} || STATUS=$?