Scheduled restic fails no output

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.

2 Likes

Are you calling restic by its full path?

Many problems like the one you’ve described are caused because people put

10 6 * * * restic <options>
instead of
10 6 * * * /usr/local/bin/restic <options>

It sounds like the crontab on that problem device might not be setup to send emails properly/at all.

2 Likes

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.

/opt/restic/run >> /var/log/restic/restic-run-log 2>&1

2 Likes

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.

1 Like

Yes, I am using full path.
The script is very simple

source /home/mike/restic.env
restic backup --compression max --exclude-caches --one-file-system --cleanup-cache /home/mike

I have the same script running on 6-7 servers, all with a crontab under root.

0 0 * * * /home/mike/backup >> /home/mike/restic.log 2>&1

The logs are always empty, but I know the job runs as it actually creates the log file.

1 Like

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.

1 Like

In your script you don’t use the full path to restic.
Not sure if source works as expected.

crontab environments (path, variables, workingdir, shell, …) may not be as expected.

You can try something like this.

(
source /home/mike/restic.env
restic backup --compression max --exclude-caches --one-file-system --cleanup-cache /home/mike
) 2>&1 | tee /tmp/test.log

not 100% sure if (…) works or if a function should used.

1 Like

I found out the problem.

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.

1 Like

That’s why I asked :wink:

2 Likes