mirror of
https://github.com/edv-pi/pbs-client-docker.git
synced 2025-04-20 07:52:56 +02:00
Add ability to block startup backup.
This commit is contained in:
parent
f19922c23c
commit
f5f1a04d97
@ -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.
|
||||||
|
@ -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,16 +18,18 @@ 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.
|
||||||
echo "## Detected backup directories:"
|
if [ ! -e "${lastrunfile}" ]; then
|
||||||
echo -e "#"
|
echo "## Detected backup directories:"
|
||||||
if [ ${#BACKUP_DIRECTORIES[@]} -eq 0 ]; then
|
echo -e "#"
|
||||||
|
if [ ${#BACKUP_DIRECTORIES[@]} -eq 0 ]; then
|
||||||
echo "# Nothing to backup."
|
echo "# Nothing to backup."
|
||||||
else
|
else
|
||||||
for path in "${BACKUP_DIRECTORIES[@]}"; do
|
for path in "${BACKUP_DIRECTORIES[@]}"; do
|
||||||
echo -e "# $path"
|
echo -e "# $path"
|
||||||
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.
|
||||||
@ -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
|
||||||
|
|
||||||
echo -e "## Backing up to repository: \n# ${PBS_REPOSITORY}\n"
|
# Print out the repository and backup command on first run only.
|
||||||
echo -e "## Executing backup command: \n# ${BACKUPCMD}\n"
|
if [ ! -e "${lastrunfile}" ]; then
|
||||||
|
echo -e "## Backing up to repository: \n# ${PBS_REPOSITORY}\n"
|
||||||
|
echo -e "## Executing backup command: \n# ${BACKUPCMD}\n"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$HEALTHCHECKSURL" ]; then
|
# 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
|
||||||
curl -fsS -m 10 --retry 5 $HEALTHCHECKSURL/start
|
curl -fsS -m 10 --retry 5 $HEALTHCHECKSURL/start
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${BACKUPCMD} 2>&1
|
# Run the actual backup command.
|
||||||
BACKUP_EXIT_CODE=$?
|
${BACKUPCMD} 2>&1
|
||||||
|
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
|
||||||
|
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
|
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
|
@ -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}"
|
||||||
|
Loading…
Reference in New Issue
Block a user