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 diff --git a/README.md b/README.md index a3acab8..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`. @@ -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_HOST` - hostname to record as source of backup +9. `RESTIC_HOST` - hostname to be used for the backup 10. `RESTIC_PASSWORD` - password for the Restic repository 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 325faa1..1c78560 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -3,21 +3,27 @@ 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 --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." 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." +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/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/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..49e5673 100755 --- a/application/restore.sh +++ b/application/restore.sh @@ -3,7 +3,15 @@ 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} --host ${RESTIC_HOST} --tag ${RESTIC_TAG} --target ${TARGET_PATH} 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." diff --git a/local.env.dist b/local.env.dist index 2a2b9f0..7a7a659 100644 --- a/local.env.dist +++ b/local.env.dist @@ -9,5 +9,6 @@ RESTIC_FORGET_ARGS= RESTIC_HOST= RESTIC_PASSWORD= RESTIC_REPOSITORY= +RESTIC_TAG= SOURCE_PATH= TARGET_PATH=