diff --git a/docker/Dockerfile b/docker/Dockerfile index 57a0505..b18c6f7 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -41,3 +41,6 @@ RUN touch etc/s6-overlay/s6-rc.d/user/contents.d/backup COPY ./src/s6-services/cron-backup /etc/s6-overlay/s6-rc.d/cron-backup RUN touch etc/s6-overlay/s6-rc.d/user/contents.d/cron-backup + +COPY ./src/helper_scripts/* /usr/local/sbin/ +RUN chmod +x /usr/local/sbin/* \ No newline at end of file diff --git a/docker/dos2unix.sh b/docker/dos2unix.sh index c1f8842..be8d404 100755 --- a/docker/dos2unix.sh +++ b/docker/dos2unix.sh @@ -1,4 +1,5 @@ #!/bin/bash # shellcheck shell=bash find . -type f \( -name "*.sh" -o -name "up" -o -name "run*" \) -exec dos2unix {} \; +find ./src/helper_scripts -type f -exec dos2unix {} \; find . -type f | xargs git update-index --chmod=+x diff --git a/docker/src/helper_scripts/lastbackup b/docker/src/helper_scripts/lastbackup new file mode 100644 index 0000000..b3d4213 --- /dev/null +++ b/docker/src/helper_scripts/lastbackup @@ -0,0 +1,12 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +lastrunfile="/tmp/pbs_client_lastrun" + +# First run touches the file. Backups will set the date. +# -s checks if the file exists and is not empty. +if [ -s "$lastrunfile" ]; then + cat "$lastrunfile" +else + echo "The first backup since container start has not happened yet." +fi \ No newline at end of file diff --git a/docker/src/s6-services/backup/run_include b/docker/src/s6-services/backup/run_include index f41c357..13aeb46 100755 --- a/docker/src/s6-services/backup/run_include +++ b/docker/src/s6-services/backup/run_include @@ -67,6 +67,9 @@ if [ "$CRON_BACKUP_ONLY" = "0" ] || [ -e "${lastrunfile}" ]; then ${BACKUPCMD} 2>&1 BACKUP_EXIT_CODE=$? + # First run touches the file. Backups will set the date. + echo "$(date +"%Y-%m-%d %H:%M:%S")" > "${lastrunfile}" + if [ -n "$HEALTHCHECKSURL" ]; then # We pipe the exit code to healthchecks, if it isn't zero, a warning will fire. curl -fsS -m 10 --retry 5 ${HEALTHCHECKSURL}/${BACKUP_EXIT_CODE} @@ -79,4 +82,5 @@ fi # Set this so backups always happen after the first run via CRON given logic above. # The date may also be useful for something like a health check if I write it... -echo "$(date +"%Y-%m-%d %H:%M:%S")" > /tmp/pbs_client_lastrun \ No newline at end of file +# First run touches the file. Backups will set the date. +touch "${lastrunfile}" \ No newline at end of file