Added option for scheduled cron
This commit is contained in:
parent
7b96dd80d5
commit
408d2d2cc3
@ -25,7 +25,8 @@ Remember to map your /etc/localtime to the /etc/localtime of the container (good
|
||||
|
||||
| NAME | VALUES | DEFAULT | DESCRIPTION |
|
||||
| :-------------- | :-------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| ENV LOG_LEVEL | 1 to 8 | 8 | Level of verbosite. Most verbose is 0, less verbose is 8 |
|
||||
| CRON_LOG_LEVEL | 1 to 8 | 8 | Level of verbosite. Most verbose is 0, less verbose is 8 |
|
||||
| CRON_SCHEDULE | a valid cron specification | empty | By default the app uses cron.daily schedule, but you can't crontrol the hour, so, is a ramdon momment during the day. If you want to schedule a fix time to run the backups define this environment variable with a valid cron_schedule. |
|
||||
| DBHOST | hostname | localhost | name of the db host to connect. |
|
||||
| USERNAME | string | postgres | user used to connects to the db. |
|
||||
| PASSWORD | string | empty | password for the user to connects to the db. Remember doing this you have the password in an environment variable. If you prefer to use Docker Secrets (I recommend this) don't define this env var or leave it blank, and go to the PASSWORD_SECRET environment variable. |
|
||||
|
@ -8,9 +8,9 @@
|
||||
# hostname:*:*:dbuser:dbpass
|
||||
# replace hostname with the value of DBHOST and postgres with
|
||||
# the value of USERNAME
|
||||
|
||||
PASSPHRASE=""
|
||||
if [ "${PASSWORD_SECRET}" ]; then
|
||||
echo "Using docker secrets..."
|
||||
if [ -f "/run/secrets/${PASSWORD_SECRET}" ]; then
|
||||
PASSPHRASE=$(cat /run/secrets/${PASSWORD_SECRET})
|
||||
else
|
||||
@ -19,13 +19,32 @@ if [ "${PASSWORD_SECRET}" ]; then
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Using environment password..."
|
||||
PASSPHRASE=${PASSWORD}
|
||||
fi
|
||||
|
||||
# Logic for the CRON schedule
|
||||
# If CRON_SCHEDULE is defined, delete the script under cron.daily and copy this one to crontab
|
||||
# If CRON_SCHEDULE is not defined, don't do anything, use default cron.daily behaviour
|
||||
if [ "${CRON_SCHEDULE}" ]; then
|
||||
echo "Configuring a CUSTOM SCHEDULE in /etc/crontab for ${CRON_SCHEDULE} ..."
|
||||
# Create the crontab file
|
||||
cat <<-EOF > /etc/crontab
|
||||
SHELL=/bin/sh
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
# m h dom mon dow user command
|
||||
${CRON_SCHEDULE} /usr/sbin/autopostgresqlbackup
|
||||
EOF
|
||||
# the file should have the correct content
|
||||
fi
|
||||
|
||||
# Create the file
|
||||
echo "Creating the password file..."
|
||||
cat <<-EOF > ${HOME}/.pgpass
|
||||
${DBHOST}:*:*:${USERNAME:-postgres}:${PASSPHRASE}
|
||||
EOF
|
||||
|
||||
# Execute cron with parameters (autopostgresql script is under /etc/cron.daily)
|
||||
exec cron -f -l ${LOG_LEVEL:-8}
|
||||
echo "Execute cron service..."
|
||||
exec cron -f -l ${CRON_LOG_LEVEL:-8}
|
||||
|
Loading…
Reference in New Issue
Block a user