I have a few servers running restic, and I have a crontab as root to do a daily backup. Most of them are working, but I have one that isn’t doing it.
I first source env file, then I run restic backup all in a single script. If I run the script manually as root, it works fine. I tried outputting the cron job to a file, and the log is empty. It just doesn’t run unless I manually run it. Other servers running exact same script work fine.
I have no idea what’s happening, it’s very weird.
I am using restic snapshots to see if there is a recent snapshot.
I put a script in /etc/cron.daily as follows. The 2>&1 bit I found online, I think it puts any output or errors into that file. You need to create the log folder and give it permissions. Using the full path of the binary can help too.
I can only recommend simply call a bash script from the crontab, and move anything fancy into the bash script. That is usually much less brittle.
That part ensures that stderr points to the same file as stdout, in your example /var/log/restic/restic-run-log. Errors that cause restic to fail are logged on stderr, thus it’s really important to also capture that output.
So you need to debug this. The fact that the log file is created doesn’t tell you much about the script running or not.
You haven’t showed us the entire script, please do. Then you can debug it by just adding code to it that prints something to a file or whatever as the first thing in the script, then another one of those right before the restic call, to determine what runs and not. Might want to also make it output the environment into a file so you can inspect that.
This only tells you that the cron job ran, it doesn’t tell you anything about what (if anything) happened in the script the job was expected to run.
I forgot to put #!/bin/bash on this particular server. The script was the same on all servers except for this, but without it, it couldn’t execute the source restic.env command properly and restic wasn’t seeing the repository.