Restic doesn't run from cron

Hi. I’m new to restic. I’ve setup an S3 bucket and repo for backups and I’m able to create snapshots with relevant commands. However, when running backups via cron, it doesn’t seem to have worked.

My system is Ubuntu 18.04. I created a bash file to run the commands that include passwords and everything. I saved this file in /usr/local/bin/backup_storage. In SSH I can run backup_storage. This works and a snapshot is created.

I created a cron with the command backup_storage and it didn’t create any snapshot. In syslog, I can see cron did execute the command.

How do I fix this? Are there any logs that could have more info?

Some random ideas:

  • How do you provide restic the repo password? Does that work in the shell cron uses?
  • Is the restic executable in the path of the shell cron uses?

You can create logfiles in your script by invoking restic like this:

restic backup >> logfile 2>> errorlogfile

I have saved the password in a file and include it in the command.
Restic is executable manually, even when run from cron.

This worked when used manually. I’ll wait till the cron runs again and update here how it goes.

Did you specify backup_storage or /usr/local/bin/backup_storage in your cronjob? Is /usr/local/bin part of your $PATH in the cronjob?

1 Like

What about actually pasting your cron line and the backup script you’re using? Otherwise people have to fumble in the dark when trying to help you. Not showing these things is like telling a mechanic that your car isn’t working, but not letting them look under the hood of the car…

PS: Check that you’re using restic 0.12.1 - it doesn’t have anything to do with your problem, but Ubuntu might have very old versions of restic in their repositories in case that’s how you installed it.

/usr/local/bin/backup_storage worked. Thanks a bunch

And so we shall never know what the problem was…

The problem was that in SSH I use backup_storage while in cron I needed to use usr/local/bin/backup_storage. You want to find out why this is? I’m not really interested in that hehe.

Because /usr/local/bin is not part of your $PATH in the crontab. Most distributions that I know set something like this:

SHELL=/bin/bash
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
MAILTO=root

You can either add your custom paths to the above line or always prefix your cron entries with the full path.

PS: Why is Discourse removing my quotes? Very annoying :angry:

2 Likes