Page 1 of 1

Help to setup cronjob with enviroment variables

Posted: Thu Aug 23, 2018 9:30 pm
by augustocarmo
Hello, I started to use VestaCP a few weeks now, and I'm just testing and making configurations before migrate my websites to a VPS.

Righ now I'm trying to setup an automated backup using restic and cron.
I installed restic and configure it with success in my server, but all the configuration was done using the root user, not the admin user. And I think that's was part of the problem.

When I configured using the root I added the environment variables to this file:

Code: Select all

/root/.bash_profile
and I can run this command:

Code: Select all

restic backup /home --exclude /home/backup
My first attempt was to just add a cron using the VestaCP panel to run this command.

Image

I can see in the log using cat /var/log/cron that the cron ran but when use the restic snapshot to list the history of backups no new snapshot is created.

Than I started to see some topics in the forum and I tried to run the same command using the admin user, and to resume I can run via ssh this command using the admin user with partial success:

Code: Select all

restic backup /home --exclude /home/backup
I get two errors:

Code: Select all

error: Open: open /home/admin/conf/dns: permission denied
error: Open: open /home/admin/conf/web: permission denied
I tried to add a cron with this command but it didn't work.

When I try to run this command:

Code: Select all

sudo restic backup /home --exclude /home/backup
The password is asked.

I really tried to fix that but is beyond my knowledge, and I would appreciate some help.

Thanks

Re: Help to setup cronjob with enviroment variables

Posted: Sat Sep 08, 2018 2:04 pm
by rhyker2u
Didn't know it was even possible to setup cronjobs from Vesta CP. However have you tried to execute:

Code: Select all

crontab -e
from ssh cli to see if it works then? And if not, to execute them as 'root' cronjobs instead of 'admin' user ?

Re: Help to setup cronjob with enviroment variables

Posted: Sun Sep 09, 2018 11:48 am
by maman
Try this

echo 'yourpassword' | sudo restic backup /home --exclude /home/backup

Re: Help to setup cronjob with enviroment variables

Posted: Mon Sep 10, 2018 3:37 pm
by augustocarmo
I added the cronjob using ssh and the root user.
I also added the environment variables in my script, that way the variables are always set before run the script.