Unable to run rclone on bash script crontab

Hello all,

good day.

im fairly new to rclone and ive been having some issues when running this as root on a bash script on my ubuntu server.

ive got the following script:
#! /bin/bash

exec 2>/home/username/trace-$$.log
set -x

find /media/backup/ -type f -name "databases_" -daystart -ctime +4 -delete
find /media/backup/ -type d -name "nextcloud-bak
" -daystart -ctime +4 -exec rm -r {} +
find /media/backup/ -type d -name "apache-bak*" -daystart -mtime +4 -exec rm -r {} +

sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --on

rsync -Aaxh /var/www/html/nextcloud/ /media/backup/Nextcloud-bak/nextcloud-bak_date +'%m-%d-%Y'/

mysqldump --all-databases > /media/backup/MySQL-bak/databases_date +'%m-%d-%Y'.sql

rsync -Aaxh /etc/apache2/sites-available/ /media/backup/Apache-conf-bak/apache-bak_date +'%m-%d-%Y'/

sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --off

RCLONE_CONFIG=/home/username/.config/rclone/rclone.conf
rclone sync /media/backups OneDrive:Backups
rclone sync /home/username/trace-$$.log OneDrive:


and for some reason, i get the following errors whe its ran with crontab as root
Failed to create file system for "OneDrive:Backups": unable to get drive_id and drive_type - if you are upgrading from older versions of rclone, please run rclone config and re-configure this backend

rclone sync /home/username/trace-30024.log OneDrive:
2020/01/14 01:00:04 Failed to create file system for "OneDrive:": unable to get drive_id and drive_type - if you are upgrading from older versions of rclone, please run rclone config and re-configure this backend


if i run this on a single script as root it works fine
#! /bin/bash

RCLONE_CONFIG=/home/username/.config/rclone/rclone.conf
rclone sync /media/backups OneDrive:Backups
rclone sync /home/username/trace-$$.log OneDrive:


can you please help me by letting me know if im missing something?
does the RCLONE_CONFIG need to go below #! /bin/bash?

thanks a lot for your advise :slight_smile:

You need an export in front of RCLONE_CONFIG so

export RCLONE_CONFIG=/home/username/.config/rclone/rclone.conf

awesome!!! ill give that a try and provide results after

another question ive got is, rclone sync would be able to remove files/directories on the remote destination if no longer on the source?

Sure that is what sync does. If you don't want that use copy.

so, i added the export in front as recommended and it worked for a file, but not for other part

here are the errors i got
rclone sync /media/backups OneDrive:Backups
2020/01/15 01:00:07 ERROR : : error reading source directory: directory not found
2020/01/15 01:00:07 ERROR : One drive root 'Backups': not deleting files as there were IO errors
2020/01/15 01:00:07 ERROR : One drive root 'Backups': not deleting directories as there were IO errors

Not sure if i was missing the/ at the end of backups or rclone was not able to delete directories in destination when syncing.
the folders in source might differ from the ones on Destination.

now my question is if sync is not copying the folders/files from source into destination.

REgards!

run that command with -vv on it and share the output and we can see what it is doing.

so i ran the command using -vv and this is what i got:

rclone sync /media/backups/ OneDrive:Backups -vv
2020/01/16 01:00:04 DEBUG : rclone: Version "v1.50.2" starting with parameters ["rclone" "sync" "/media/backups/" "OneDrive:Backups" "-vv"]
2020/01/16 01:00:04 DEBUG : Using config file from "/home/username/.config/rclone/rclone.conf"
2020/01/16 01:00:04 DEBUG : OneDrive: Loaded invalid token from config file - ignoring
2020/01/16 01:00:06 DEBUG : Keeping previous permissions for config file: -rw-r--r--
2020/01/16 01:00:06 DEBUG : OneDrive: Saved new token in config file
2020/01/16 01:00:07 ERROR : : error reading source directory: directory not found
2020/01/16 01:00:07 INFO : One drive root 'Backups': Waiting for checks to finish
2020/01/16 01:00:07 INFO : One drive root 'Backups': Waiting for transfers to finish
2020/01/16 01:00:07 ERROR : One drive root 'Backups': not deleting files as there were IO errors
2020/01/16 01:00:07 ERROR : One drive root 'Backups': not deleting directories as there were IO errors
2020/01/16 01:00:07 ERROR : Attempt 1/3 failed with 2 errors and: directory not found
2020/01/16 01:00:08 ERROR : : error reading source directory: directory not found
2020/01/16 01:00:08 INFO : One drive root 'Backups': Waiting for checks to finish
2020/01/16 01:00:08 INFO : One drive root 'Backups': Waiting for transfers to finish
2020/01/16 01:00:08 ERROR : One drive root 'Backups': not deleting files as there were IO errors
2020/01/16 01:00:08 ERROR : One drive root 'Backups': not deleting directories as there were IO errors
2020/01/16 01:00:08 ERROR : Attempt 2/3 failed with 2 errors and: directory not found
2020/01/16 01:00:08 ERROR : : error reading source directory: directory not found
2020/01/16 01:00:08 INFO : One drive root 'Backups': Waiting for checks to finish
2020/01/16 01:00:08 INFO : One drive root 'Backups': Waiting for transfers to finish
2020/01/16 01:00:08 ERROR : One drive root 'Backups': not deleting files as there were IO errors
2020/01/16 01:00:08 ERROR : One drive root 'Backups': not deleting directories as there were IO errors
2020/01/16 01:00:08 ERROR : Attempt 3/3 failed with 2 errors and: directory not found
2020/01/16 01:00:08 Failed to sync with 2 errors: last error was: directory not found

rclone sync /home/username/trace-23204.log OneDrive: <--- this one works normally, no issues syncing

now, there are newer directories on the source that have not yet been copied/sync to the destination due to this, so, not sure if i need to delete all the current folders on the destination and then run the sync again.

You are getting an error reading the source.

What does

rclone ls /media/backups/

show?

i think i just found my issue... :blush:

turns out i was listing the wrong directory in my script... :frowning:

instead of reading /media/backup which is the correct directory, i was trying to read /media/backups (with an additional 's')

when doing the ls /media/backups/ i realized that typo...

i just fixed this on my script and more than likely this will get everything fixed...

ill provide an update tomorrow after the next run.

Regards!

Oh we've all been there! Happy to see you think you found it.

So, I updated my script with the correct path and now, sync is working as expected.

It’s updating and deleting folders as expected.

Thanks again for your input and help on this.

2 Likes