docker-pg-backup icon indicating copy to clipboard operation
docker-pg-backup copied to clipboard

Add logging

Open YuryHrytsuk opened this issue 1 year ago • 9 comments

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'

YuryHrytsuk avatar Nov 03 '23 09:11 YuryHrytsuk

You should be able to check the cron logs https://github.com/kartoza/docker-pg-backup/blob/master/build_data/backups-cron#L2C47-L2C63

NyakudyaA avatar Nov 03 '23 09:11 NyakudyaA

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?

YuryHrytsuk avatar Nov 03 '23 10:11 YuryHrytsuk

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

NyakudyaA avatar Nov 03 '23 10:11 NyakudyaA

Or just add your own custom cron file with that logic

-v ./backups-cron:/settings/backups-cron

NyakudyaA avatar Nov 03 '23 10:11 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

YuryHrytsuk avatar Nov 15 '23 08:11 YuryHrytsuk

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

YuryHrytsuk avatar Nov 15 '23 12:11 YuryHrytsuk

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

YuryHrytsuk avatar Nov 15 '23 13:11 YuryHrytsuk

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

NyakudyaA avatar Nov 15 '23 18:11 NyakudyaA

Another easier option is to add

If [ Logging== True] ;then
Logging=/dev/stdout
else
Logging=
Fi

NyakudyaA avatar Nov 15 '23 18:11 NyakudyaA