modem7 / docker-borgmatic

Container to automate Borgbackups (https://github.com/borgbackup) using Borgmatic (https://github.com/witten/borgmatic)
MIT License
29 stars 5 forks source link

Crontab.txt does not run borgmatic on schedule #134

Closed televisi closed 5 months ago

televisi commented 5 months ago

Hi,

This might not likely an issue, but more a discussion; but because I cannot see 'discussions' tab on your github, I raised it under 'issue' instead.

As part of the testing, I wanted to have borgmatic to run every 3 minutes followed with logrotate command every 5 minutes.

On \etc\borgmatic.d\crontab.txt file, I have the following

*/3 1 * * * PATH=$PATH:/usr/local/bin /usr/local/bin/borgmatic --stats -v 0 --log-file /etc/borgmatic.d/log/borgmatic.log --log-file-verbosity 1 2>&1
#run logrotate to borgmatic log file every 15th minute
*/5 * * * * bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'

When I checked docker log, it only ran the logrotate every 5 minutes, but does not run the borgmatic; did I miss anything here?

INFO[2024-01-30T06:57:42+11:00] read crontab: /etc/borgmatic.d/crontab.txt   
INFO[2024-01-30T06:57:42+11:00] crontab is valid                             
The variable SUPERCRONIC_EXTRA_FLAGS is empty, starting normally
INFO[2024-01-30T06:57:42+11:00] read crontab: /etc/borgmatic.d/crontab.txt   
INFO[2024-01-30T07:00:00+11:00] starting                                      iteration=0 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:00:00+11:00] job succeeded                                 iteration=0 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:05:00+11:00] starting                                      iteration=1 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:05:00+11:00] job succeeded                                 iteration=1 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:10:00+11:00] starting                                      iteration=2 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:10:00+11:00] job succeeded                                 iteration=2 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:15:00+11:00] starting                                      iteration=3 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:15:00+11:00] job succeeded                                 iteration=3 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:20:00+11:00] starting                                      iteration=4 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:20:00+11:00] job succeeded                                 iteration=4 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:25:00+11:00] starting                                      iteration=5 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"
INFO[2024-01-30T07:25:00+11:00] job succeeded                                 iteration=5 job.command="bash -c 'logrotate /etc/borgmatic.d/logrotate.conf'" job.position=1 job.schedule="*/5 * * * *"

Thanks

modem7 commented 5 months ago

I'd recommend trying the CRON, CRON_COMMAND and EXTRA_CRON variables to see if that works better for you.

Make sure to remove the contab.

This makes it much easier to modify as you wish during testing as you can just bring the compose file up again.

Example:

    environment:
      TZ: $TZ
      CRON: 0 5 * * *
      CRON_COMMAND: borgmatic --stats -v 0
      EXTRA_CRON: |-
        0 5 2 * * command1
        0 7 1 * * command2

More info: https://github.com/modem7/docker-borgmatic?tab=readme-ov-file#environment-variables

televisi commented 5 months ago

Thanks for your prompt reply!

Okay, I just gave this a try:

Unfortunately, it didn't work. When I checked the /etc/borgmatic.d/ folder, seems the crontab.txt is created again, with this content:

0 1 * * * PATH=$PATH:/usr/local/bin /usr/local/bin/borgmatic --stats -v 0 2>&1

Log:

INFO[2024-01-30T07:51:00+11:00] read crontab: /etc/borgmatic.d/crontab.txt   
INFO[2024-01-30T07:51:00+11:00] crontab is valid                             
The variable SUPERCRONIC_EXTRA_FLAGS is empty, starting normally
INFO[2024-01-30T07:51:00+11:00] read crontab: /etc/borgmatic.d/crontab.txt
modem7 commented 5 months ago

SUPERCRONIC_EXTRA_FLAGS?

Could you double-check which image you're using?

televisi commented 5 months ago

Could you double-check which image you're using?

Ugh! you're right, I was using the other image from borgmatic-collective; ugh! sorry!

I have found your wiki was super useful and didn't realise that I use the image from the other one.

I'll reach out to the other github for this issue and closing this one.

modem7 commented 5 months ago

Thank you! Glad the wiki helped!

You can use either, but they both have different variables available.

I'm one of the maintainer in the main repo, but there were a few things I'm using in mine that the other hasn't yet got.

So they'd both work similarly, but have slightly different behaviour depending on the config (eg this one has docker, different cron job settings, s6 etc).

Neither one is better than the other, but they cater to different use cases.