docker-pg-backup
docker-pg-backup copied to clipboard
Add logging
Feature description
I want to see in the containers logs when it starts creating a backup, when if finishes, what was created and, if failed, some logs to understand the context of failure. The date time of the logs will be also helpful.
Additional context
Whenever for some reason you don't find a backup file you have no idea what happened and the containers logs stay always empty.
Start script running with these environment options
DUMPPREFIX=PG_backup
PG_CONN_PARAMETERS='-h production_postgres -p 5432 -U postgres'
You should be able to check the cron logs https://github.com/kartoza/docker-pg-backup/blob/master/build_data/backups-cron#L2C47-L2C63
You should be able to check the cron logs https://github.com/kartoza/docker-pg-backup/blob/master/build_data/backups-cron#L2C47-L2C63
Is it possible show these logs in container's logs?
https://stackoverflow.com/questions/45395390/see-cron-output-via-docker-logs-without-using-an-extra-file, I suggest you do a PR with the suggested changes here
Or just add your own custom cron file with that logic
-v ./backups-cron:/settings/backups-cron
Or just add your own custom cron file with that logic
-v ./backups-cron:/settings/backups-cron
It looks like this file will never be used because of these lines:
https://github.com/kartoza/docker-pg-backup/blob/b55f20c57c52834298facfc70b427c9601ed8d3d/scripts/start.sh#L131-L134
Or just add your own custom cron file with that logic
-v ./backups-cron:/settings/backups-cron
It looks like this file will never be used because of these lines:
https://github.com/kartoza/docker-pg-backup/blob/b55f20c57c52834298facfc70b427c9601ed8d3d/scripts/start.sh#L131-L134
I found a workaround: -v ./custom-backups-cron:/build_data/backups-cron
.
However, it will still NOT work because inside scripts logs are directly written to the /var/log/cron.log
. For example, https://github.com/kartoza/docker-pg-backup/blob/b55f20c57c52834298facfc70b427c9601ed8d3d/scripts/backups.sh#L94
I finally ended up with this:
volumes:
- ./custom-backups-cron:/build_data/backups-cron # redirect logs to /dev/stdout
- ./custom-backups.sh:/backup-scripts/backups.sh
First volume is to redirect cron job output to /dev/stdout
, i.e.
${CRON_SCHEDULE} /backup-scripts/backups.sh > /proc/1/fd/1 2>&1
Second volume simply removes all >> /var/log/cron.log
entries to avoid writing to file.
I will see how it flies. If it works fine, I will create PR @NyakudyaA
Or just add your own custom cron file with that logic
-v ./backups-cron:/settings/backups-cron
It looks like this file will never be used because of these lines:
https://github.com/kartoza/docker-pg-backup/blob/b55f20c57c52834298facfc70b427c9601ed8d3d/scripts/start.sh#L131-L134
Wouldn't it make sense to adjust the function cron_config(), I think the logic should be If cron file exists in extra_config dir then use it else set default from internal
Another easier option is to add
If [ Logging== True] ;then
Logging=/dev/stdout
else
Logging=
Fi