Add ability to block startup backup.

This commit is contained in:
Aterfax 2024-03-26 22:36:08 +00:00
parent f19922c23c
commit f5f1a04d97
No known key found for this signature in database
GPG Key ID: 51E7ED3290C121FE
3 changed files with 43 additions and 23 deletions

View File

@ -3,6 +3,8 @@ PBS_ENCRYPTION_PASSWORD="123456789abcdefghijklmn"
PBS_ENDPOINT="pbs.mydomain.com" PBS_ENDPOINT="pbs.mydomain.com"
PBS_DATASTORE="test-datastore" PBS_DATASTORE="test-datastore"
CRON_SCHEDULE="0 */4 * * *" CRON_SCHEDULE="0 */4 * * *"
# If you want to skip backup on startup, set CRON_BACKUP_ONLY=1 otherwise CRON_BACKUP_ONLY=0
CRON_BACKUP_ONLY=0
# Use of the PBS_API_KEY_NAME and PBS_API_KEY_SECRET is recommended! # Use of the PBS_API_KEY_NAME and PBS_API_KEY_SECRET is recommended!
# If unset, ensure PBS_USER and PBS_PASSWORD are set. # If unset, ensure PBS_USER and PBS_PASSWORD are set.

View File

@ -8,6 +8,8 @@ path_to_filename() {
echo "${filename}" echo "${filename}"
} }
lastrunfile="/tmp/pbs_client_lastrun"
BACKUP_DIRECTORIES=() BACKUP_DIRECTORIES=()
# Iterate over each subdirectory under /backup and add its full path to the array # Iterate over each subdirectory under /backup and add its full path to the array
for dir in /backups/*; do for dir in /backups/*; do
@ -16,7 +18,8 @@ for dir in /backups/*; do
fi fi
done done
# Print the contents of the array # Print the contents of the array if this is first run only.
if [ ! -e "${lastrunfile}" ]; then
echo "## Detected backup directories:" echo "## Detected backup directories:"
echo -e "#" echo -e "#"
if [ ${#BACKUP_DIRECTORIES[@]} -eq 0 ]; then if [ ${#BACKUP_DIRECTORIES[@]} -eq 0 ]; then
@ -27,6 +30,7 @@ else
done done
echo -e "#\n" echo -e "#\n"
fi fi
fi
# Construct the directory target list with the proxmox-backup-client syntax. # Construct the directory target list with the proxmox-backup-client syntax.
# This makes 1 .pxar file per path. # This makes 1 .pxar file per path.
@ -43,20 +47,36 @@ if [ -n "$PBS_DATASTORE_NS" ]; then
BACKUPCMD+=" --ns ${PBS_DATASTORE_NS}" BACKUPCMD+=" --ns ${PBS_DATASTORE_NS}"
fi fi
# Source the variables from the setup_check scripting include file. # Source the variables from the setup_check scripting include file.
source /etc/s6-overlay/s6-rc.d/setup_check/run_include source /etc/s6-overlay/s6-rc.d/setup_check/run_include
# Print out the repository and backup command on first run only.
if [ ! -e "${lastrunfile}" ]; then
echo -e "## Backing up to repository: \n# ${PBS_REPOSITORY}\n" echo -e "## Backing up to repository: \n# ${PBS_REPOSITORY}\n"
echo -e "## Executing backup command: \n# ${BACKUPCMD}\n" echo -e "## Executing backup command: \n# ${BACKUPCMD}\n"
fi
# Note the first evaluation is key and will initiate backup if the user opts
# to allow the first backup or we're
if [ "$CRON_BACKUP_ONLY" = "0" ] || [ -e "${lastrunfile}" ]; then
if [ -n "$HEALTHCHECKSURL" ]; then if [ -n "$HEALTHCHECKSURL" ]; then
curl -fsS -m 10 --retry 5 $HEALTHCHECKSURL/start curl -fsS -m 10 --retry 5 $HEALTHCHECKSURL/start
fi fi
# Run the actual backup command.
${BACKUPCMD} 2>&1 ${BACKUPCMD} 2>&1
BACKUP_EXIT_CODE=$? BACKUP_EXIT_CODE=$?
if [ -n "$HEALTHCHECKSURL" ]; then 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} curl -fsS -m 10 --retry 5 ${HEALTHCHECKSURL}/${BACKUP_EXIT_CODE}
fi fi
elif [ "$CRON_BACKUP_ONLY" = "1" ]; then
echo "CRON_BACKUP_ONLY=1, skipping container start up initial backup."
elif [ "$CRON_BACKUP_ONLY" = "0" ] || [ "$CRON_BACKUP_ONLY" = "1" ] ]; then
echo "CRON_BACKUP_ONLY set to invalid value, skipping container start up initial backup."
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

View File

@ -1,8 +1,6 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
# shellcheck shell=bash # shellcheck shell=bash
echo -e "## Conducting variable checks."
# If an API key is set we should use it over any password / username. # If an API key is set we should use it over any password / username.
if [ -n "$PBS_API_KEY_SECRET" ]; then if [ -n "$PBS_API_KEY_SECRET" ]; then
PBS_PASSWORD="${PBS_API_KEY_SECRET}" PBS_PASSWORD="${PBS_API_KEY_SECRET}"