Hi,
I've read different similar issue but nothing...
I've a very simple backup.sh file:
#!/bin/bash
rm /BackUp/Files/*
cd /BackUp/Files
zip -r BackUp_$(date '+%d-%b-%Y_%T').zip /var/www
/usr/local/bin/gdrive upload /BackUp/Files/*
and i set crontab:
sh /BackUp/backup.sh
the scripts run, create the zip correctly but don't upload the file, if I run it from terminal ' sudo sh /BackUp/backup.sh' all go correctly
Any ideas?
@Selektion You said that it was a permission error in the referenced issue. Can you confirm that this is the case?
I have the same problem.
This is my bash script
#!/usr/bin/env bash
/usr/local/bin/gdrive -c ~/.gdrive list > /var/www/myweb/list.txt
This is my cron
10 12 * * * root /var/www/myweb/list.sh
When I executed the command directly, it worked but. But it didn't work using cron
Can anybody help?
there is a solution on this issue #151
Hi everybody,
gdrive does not work in crontab, I have already done all the suggestions above and I still does not work.
Can anybody help?
Thanks.
Hello,
Please run command echo $PATH in your server and show result here.
Hello @mbrother2
This is my path in root mode:
/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
gdrive is locale in:
gdrive: /usr/bin/gdrive
my crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
MAILTO=root
HOME=/
19 00 * * * root /home/user/code/backup_to_drive.sh
when I run the script manually it works, but from the crontab does not work.
Hello @DeiverJC,
Please try
```SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
MAILTO=root
HOME=/
19 00 * * * sh /home/user/code/backup_to_drive.sh
Hi @mbrother2,
Thanks for you answer, but it still does not work.
I don't understand why, already reinstall gdrive as root, my server is running centos 7.
Hello @DeiverJC,
Please show your scirpt to backup your data.
@mbrother2, This is my script:
#!/bin/bash
backupPath = "/home/user/BACKUPS/"
folders = `ls /home/user/BACKUPS/`
yesterday = $(date +%Y_%m_%d --date='-1 day')
beforeYesterday = $(date +%Y_%m_%d --date='-2 day')
cloudFolder=`gdrive list --no-header --query "name = 'BACKUPS'" -m 1`
for lnk in $folders
do
filesToDelete = `gdrive list --no-header --query "name = '$beforeYesterday.zip'" -m 1`
if [ "${filesToDelete[0]:0:1}" != "" ];
then
gdrive delete -r ${filesToDelete[0]:0:33}
fi
folder=`gdrive list --no-header --query "name = '$lnk'" -m 1`
if [ "${folder[0]:0:1}" = "" ];
then
gdrive upload -r --parent ${cloudFolder[0]:0:33} "$backupPath$lnk/"
else
gdrive upload -r --parent ${folder[0]:0:33} "$backupPath$lnk/$yesterday.zip"
fi
done
Hello @DeiverJC,
First, your bash script has syntax errors( white space when assign variable). I modified it, please try
#!/bin/bash
backupPath="/home/user/BACKUPS/"
folders=`ls /home/user/BACKUPS/`
yesterday=$(date +%Y_%m_%d --date='-1 day')
beforeYesterday=$(date +%Y_%m_%d --date='-2 day')
cloudFolder=`gdrive list --no-header --query "name = 'BACKUPS'" -m 1`
for lnk in $folders
do
filesToDelete=`gdrive list --no-header --query "name = '$beforeYesterday.zip'" -m 1`
if [ "${filesToDelete[0]:0:1}" != "" ];
then
gdrive delete -r ${filesToDelete[0]:0:33}
fi
folder=`gdrive list --no-header --query "name = '$lnk'" -m 1`
if [ "${folder[0]:0:1}" = "" ];
then
gdrive upload -r --parent ${cloudFolder[0]:0:33} "$backupPath$lnk/"
else
gdrive upload -r --parent ${folder[0]:0:33} "$backupPath$lnk/$yesterday.zip"
fi
done
Second, try to move your script to /usr/sbin directory and chmod 755
mv /home/user/code/backup_to_drive.sh /usr/sbin/backup_to_drive.sh
chmod 755 /usr/sbin/backup_to_drive.sh
Third, edit your cron and restart crond service
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
19 00 * * * sh /usr/sbin/backup_to_drive.sh
systemctl restart crond
I try above steps on my server and cron worked perfectly. Good luck!
Hi @mbrother2,
Thank you so much for you support.
I try your directions and it did not work, but add sudo before gdrive and it worked.
folder=`sudo gdrive list --no-header --query "name = '$lnk'" -m 1`
if [ "${folder[0]:0:1}" = "" ];
then
sudo gdrive upload -r --parent ${cloudFolder[0]:0:33} "$backupPath$lnk/"
else
sudo gdrive upload -r --parent ${folder[0]:0:33} "$backupPath$lnk/$yesterday.zip"
fi
Thanks again for your help. <3
Hello @DeiverJC,
You're welcome!
Most helpful comment
I have the same problem.
This is my bash script
This is my cron
10 12 * * * root /var/www/myweb/list.shWhen I executed the command directly, it worked but. But it didn't work using cron
Can anybody help?