I am looking at adding in crontab the command to automatically generate the backups with restic.
The command I execute in cron is the following:
*/1 * * * * source /root/.bashrc; /usr/bin/restic -r $RESTIC_REPOSITORY backup /home/vmail/domain.com --tag FromCron >> /var/log/restic.log 2>> /var/log/restic.log
I have looked at redirecting the output of the commands in files to review it and I get the following:
unknown command "/home/vmail/domain.com" for "restic"
It’s as if the command doesn’t understand that what is happening is the backup path. I have also tried to execute it with a script and it gives the same error. Does anyone know that I am leaving?
Sounds like it’s treating the
restic part as a username. In which file or how are you adding this crontab entry to cron?
I’m adding it with crontab -e
I have also tried to add it in /etc/crontab but the same error remains:
*/1 * * * * root /usr/bin/restic -r $RESTIC_REPOSITORY backup /home/vmail/domain.com --tag FromCron >> /var/log/restic.log 2>> /var/log/restic.log
Did you edit your initial post (the crontab line) after I wrote my first reply?
I’m pretty sure the problem is that the command is evaluated as
/usr/bin/restic -r backup /home/vmail/domain.com --tag FromCron >> /var/log/restic.log 2>> /var/log/restic.log. That would yield the error message you are seeing.
The problem is that your environment variable, $RESTIC_REPOSITORY resolves to an empty string.
I haven’t changed anything from my first message. I only updated my second comment.
Uhm, I just checked and it seems that there is a problem with the environment variable
I have modified it and now I get this error
Fatal: unable to open config file: Stat: Access Denied.
Is there a repository at the following location?
This time I added it in /etc/crontab by adding the user, as in my second comment.
If I execute the same command through CLI it works correctly. What it could be?
No idea but presumably authentication information not going through as it should, assuming the commands that are run are the exact same ones when it works and doesn’t. Check your environment variables for S3 and the authentication, verify that they are truly coming through and have a proper value in the environment that the command is run in using cron?
I have already found out what was wrong. In fact, the environment variables were not working correctly. I had to add
. /root/.bashrc in the cron line to make it work correctly.
*/1 * * * * . /root/.bashrc; /usr/bin/restic -r $RESTIC_REPOSITORY backup /home/vmail/domain.com --tag FromCron >> /var/log/restic.log 2>> /var/log/restic.log
Thank you very much for your help! I’ve been trying Restic for months and I really love it!
Glad to hear that it worked out!