Fix lastrunfile logic and add lastbackup helper script.

This commit is contained in:
Aterfax 2024-03-26 22:52:15 +00:00
parent f5f1a04d97
commit aa90a87bc9
No known key found for this signature in database
GPG Key ID: 51E7ED3290C121FE
4 changed files with 21 additions and 1 deletions

View File

@ -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/*

View File

@ -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

View File

@ -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

View File

@ -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
# First run touches the file. Backups will set the date.
touch "${lastrunfile}"