Unable to use sudo to sync to gdrive

What is the problem you are having with rclone?

I have a handful of permission denied errors when syncing to gdrive. When I try to run the command with sudo, I get an error that suggests the my token may have expired. This is not the case as it works correctly when sudo is removed. I am able to do a local backup using sudo.

What is your rclone version (output from rclone version)

rclone v1.55.0
- os/type: linux
- os/arch: arm64
- go/version: go1.16.2
- go/linking: static
- go/tags: cmount

Which OS you are using and how many bits (eg Windows 7, 64 bit)

linux arm64

Which cloud storage system are you using? (eg Google Drive)

local and google drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

sudo rclone sync pi:/ google:/habackup/21-06-10.2 --progress --filter-from /docker/rclonefilter

and

rclone sync pi:/ google:/habackup/21-06-10.2 --progress --filter-from /docker/rclonefilter

The rclone config contents with secrets removed.

[google]
type = drive
client_id = [secret?]
client_secret = [secret]
scope = drive
token = [secret?]
[pi]
type = local
copy_links = true
no_check_updated = true

A log from the command with the -vv flag

2021/06/10 15:41:18 DEBUG : Using config file from "/root/.config/rclone/rclone.conf"
2021/06/10 15:41:18 DEBUG : rclone: Version "v1.55.0" starting with parameters ["rclone" "sync" "pi:/" "google:/habackup/21-06-10.2" "-vv" "--progress" "--filter-from" "/docker/rclonefilter"]
2021/06/10 15:41:18 DEBUG : Creating backend with remote "pi:/"
2021/06/10 15:41:18 DEBUG : Creating backend with remote "google:/habackup/21-06-10.2"
2021/06/10 15:41:18 DEBUG : google: Loaded invalid token from config file - ignoring
2021/06/10 15:41:18 DEBUG : google: Token refresh failed try 1/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
2021/06/10 15:41:19 DEBUG : google: Loaded invalid token from config file - ignoring
2021/06/10 15:41:19 DEBUG : google: Token refresh failed try 2/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
2021/06/10 15:41:20 DEBUG : google: Loaded invalid token from config file - ignoring
2021/06/10 15:41:20 DEBUG : google: Token refresh failed try 3/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
2021/06/10 15:41:21 DEBUG : google: Loaded invalid token from config file - ignoring
2021/06/10 15:41:22 DEBUG : google: Token refresh failed try 4/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
2021/06/10 15:41:23 DEBUG : google: Loaded invalid token from config file - ignoring
2021/06/10 15:41:23 DEBUG : google: Token refresh failed try 5/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
2021/06/10 15:41:24 Failed to create file system for "google:/habackup/21-06-10.2": couldn't find root directory ID: Get "https://www.googleapis.com/drive/v3/files/root?alt=json&fields=id&prettyPrint=false&supportsAllDrives=true": couldn't fetch token - maybe it has expired? - refresh with "rclone config reconnect google:": oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

Looks like you need to reconnect to your account:

https://rclone.org/commands/rclone_config_reconnect/

That doesn't appear to be the case, because the command works when I don't use sudo.

hello and welcome to the forum,

what operating system on the pi?

if you run a command as sudo, it runs as root user, and that user would have a different config file, then a non-sudo user.
that is how it works on my pi

ubuntu@ubuntu:~$ rclone config file
Configuration file is stored at:
/home/ubuntu/.config/rclone/rclone.conf
ubuntu@ubuntu:~$ sudo rclone config file
2021/06/10 16:54:46 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
Configuration file doesn't exist, but rclone will use this path:
/root/.config/rclone/rclone.conf

you can choose the location of the config file with
https://rclone.org/docs/#config-config-file

1 Like

Awesome, thank you. This is the solution.

That was the case as you were using a different config file that had the account not connected.

Yes, that's right. I didn't realize that there were 2 config files.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.