Help to setup cronjob with enviroment variables
-
- Posts: 10
- Joined: Thu Aug 23, 2018 8:58 pm
- Os: CentOS 6x
- Web: nginx + php-fpm
Help to setup cronjob with enviroment variables
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: and I can run this command:
My first attempt was to just add a cron using the VestaCP panel to run this command.
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:
I get two errors:
I tried to add a cron with this command but it didn't work.
When I try to run this command:
The password is asked.
I really tried to fix that but is beyond my knowledge, and I would appreciate some help.
Thanks
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
Code: Select all
restic backup /home --exclude /home/backup
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
Code: Select all
error: Open: open /home/admin/conf/dns: permission denied
error: Open: open /home/admin/conf/web: permission denied
When I try to run this command:
Code: Select all
sudo restic backup /home --exclude /home/backup
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
Didn't know it was even possible to setup cronjobs from Vesta CP. However have you tried to execute:
from ssh cli to see if it works then? And if not, to execute them as 'root' cronjobs instead of 'admin' user ?
Code: Select all
crontab -e
Re: Help to setup cronjob with enviroment variables
Try this
echo 'yourpassword' | sudo restic backup /home --exclude /home/backup
echo 'yourpassword' | sudo restic backup /home --exclude /home/backup
-
- Posts: 10
- Joined: Thu Aug 23, 2018 8:58 pm
- Os: CentOS 6x
- Web: nginx + php-fpm
Re: Help to setup cronjob with enviroment variables
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.
I also added the environment variables in my script, that way the variables are always set before run the script.