Rclone delete --rmdirs didn't remove the empty directories - Google Drive

Running the below command for Google Drive;

rclone delete remote:/backup --min-age 3d --drive-use-trash=false --rmdirs -v

under /backup there are subfolders again created by rclone move such as 24-04-2021; 25-04-2021 ... etc.

Command above works great it deletes all the files if their ages are >3d and skips Trash; however; it cannot remove the directories. Now I have empty directories like /23-04-2021 , /24-04-2021 ....

Similarly I tried to run the command below but it couldn't remove the folders.

rclone rmdir remote:/backup --min-age 3d --drive-use-trash=false -v

Only the way to remove the empty folder is adding the path like; rclone rmdir remote:/backup/23-04-2021, which is not convenient for my back-up process.

Any idea why rclone delete --rmdirs not working?? (tested it in both rclone v1.55 and v1.55.1)

You need to include some details and a log file and we can see what's going on.

Why did you delete the help and support template and not use it?

Because empty folders or related processes are not in the log; here is the the help and support template:

What is the problem you are having with rclone?

Empty dirs in Google drive cannot be removed with delete --rmdirs

What is your rclone version (output from rclone version)

rclone v1.55.1

  • os/type: linux
  • os/arch: amd64
  • go/version: go1.16.3
  • go/linking: static
  • go/tags: none

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

Ubuntu 20.04

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

Google Drive

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

rclone delete remote:/backup --min-age 3d --drive-use-trash=false --rmdirs -v

The rclone config contents with secrets removed.

[remote]
type = drive
scope = drive
token = {"access_token":"*****","token_type":"Bearer","refresh_token":"****","expiry":"2021-04-30T01:44:36.505225809Z"}
root_folder_id = ********

A log from the command with the -vv flag

`root@oci:/home/ubuntu# rclone delete remote:/backup --min-age 3d  -vv
2021/04/30 00:44:37 DEBUG : Using config file from "/root/.config/rclone/rclone.conf"
2021/04/30 00:44:37 DEBUG : --min-age 3d to 2021-04-27 00:44:37.23812187 +0000 UTC m=-259199.584741197
2021/04/30 00:44:37 DEBUG : rclone: Version "v1.55.1" starting with parameters ["rclone" "delete" "remote:/backup" "--min-age" "3d" "-vv"]
2021/04/30 00:44:37 DEBUG : Creating backend with remote "remote:/backup"
2021/04/30 00:44:37 DEBUG : remote: Loaded invalid token from config file - ignoring
2021/04/30 00:44:37 DEBUG : Saving config "token" = "{\"access_token\":\"ya29.a0AfH6SMBTZmABKIowrAnRmDoi85htiZOh3N0AheS3nu0h5vt_72p7uR0tIEm99JVbd4jD7dlS20w0ZsSIGaxRKss0y_5-sycMwyXGfjpLm8V_A_bvgQcyQrMD-oz_TyARt31rT5KMRCBou-T_xbYRXB7BP8Koow\",\"token_type\":\"Bearer\",\"refresh_token\":\"1//037Srl2q46wiiCgYIARAAGAMSNwF-L9IrAOxbBDTEWpmTUm1nhMHJozz6fQb9qBgVUK3XA27D9j3MB8Hg8zVryd0UH_jUzAw5qqw\",\"expiry\":\"2021-04-30T01:44:36.505225809Z\"}" in section "remote" of the config file
2021/04/30 00:44:37 DEBUG : remote: Saved new token in config file
2021/04/30 00:44:38 DEBUG : fs cache: renaming cache item "remote:/backup" to be canonical "remote:backup"
2021/04/30 00:44:38 DEBUG : Waiting for deletions to finish
2021/04/30 00:44:38 DEBUG : 27-04-2021/virtualmin.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain1.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain1.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain2.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain2.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain3.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain3.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain4.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain4.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain5.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain5.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain6.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain6.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain7.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain7.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain8.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain8.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/virtualmin.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain1.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain2.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain3.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain4.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain5.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain6.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain7.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 27-04-2021/domain8.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/virtualmin.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain1.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain1.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain2.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain2.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain3.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain3.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain4.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain4.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain5.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain5.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain6.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain6.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain7.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain7.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain8.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain8.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/virtualmin.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain1.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain2.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain3.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain4.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain5.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain6.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain7.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 29-04-2021/domain8.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/virtualmin.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain1.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain1.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain2.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain2.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain3.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain3.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain4.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain4.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain5.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain5.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain6.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain6.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain7.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain7.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain8.com.tar.gz.dom: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain8.com.tar.gz.info: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/virtualmin.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain1.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain2.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain3.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain4.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain5.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain6.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain7.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 28-04-2021/domain8.com.tar.gz: Excluded from sync (and deletion)
2021/04/30 00:44:38 DEBUG : 12 go routines active`

What's the empty dir that should be removed? Can you do a rclone ls on the path for that?

rclone ls didn't show the empty directory but lsd showed;

rclone lsd remote:/backup
-1 2021-04-26 17:47:29 -1 26-04-2021 this one should have been removed
-1 2021-04-27 21:47:45 -1 27-04-2021
-1 2021-04-28 21:45:55 -1 28-04-2021
-1 2021-04-29 21:47:53 -1 29-04-2021

Also rclone ls remote:/backup/26-04-2021 returned nothing; no subfolders no files.

From the rclone delete docs

--rmdirs   rmdirs removes empty directories but leaves root intact

If you want to remove the dir and all of its contents then you want rclone purge. Some cloud providers (including google drive) have a short cut for this so it is a quick operation.

The OP has some filters though so purge wouldn't obey them if I understand the scenario properly.

I don't see an issue with rmidrs as it works as expected for me on a local test.

felix@gemini:~/test$ ls
test1  test2
felix@gemini:~/test$
felix@gemini:~/test$
felix@gemini:~/test$ rclone delete /home/felix/test --rmdirs -vv
2021/04/30 07:51:57 DEBUG : Using config file from "/opt/rclone/rclone.conf"
2021/04/30 07:51:57 DEBUG : rclone: Version "v1.55.1" starting with parameters ["rclone" "delete" "/home/felix/test" "--rmdirs" "-vv"]
2021/04/30 07:51:57 DEBUG : Creating backend with remote "/home/felix/test"
2021/04/30 07:51:57 DEBUG : Waiting for deletions to finish
2021/04/30 07:51:57 INFO  : test2/blah: Deleted
2021/04/30 07:51:57 DEBUG : test2: Removing directory
2021/04/30 07:51:57 DEBUG : test1: Removing directory
2021/04/30 07:51:57 DEBUG : 2 go routines active
felix@gemini:~/test$ ls
felix@gemini:~/test$

If that is empty, "rclone delete remote:backup --rmdirs" should remove that as well.

In this scenario; root is /backup and empty 26-04-2021 folder is sub and should be removed with --rmdirs, am I right? If so; "leaves root intact" is for just /backup not the empty folders inside.

Exactly, that's my point; it should have removed the empty dirs. I'm not sure, perhaps --rmdirs behave improperly for Google Drive.

Works fine on GD for me as well:

felix@gemini:~$ rclone mkdir GD:test/test1
felix@gemini:~$ rclone mkdir GD:test/test2
felix@gemini:~$ rclone delete GD:test --rmdirs -vv
2021/04/30 08:37:40 DEBUG : Using config file from "/opt/rclone/rclone.conf"
2021/04/30 08:37:40 DEBUG : rclone: Version "v1.55.1" starting with parameters ["rclone" "delete" "GD:test" "--rmdirs" "-vv"]
2021/04/30 08:37:40 DEBUG : Creating backend with remote "GD:test"
2021/04/30 08:37:41 DEBUG : Waiting for deletions to finish
2021/04/30 08:37:42 DEBUG : test2: Removing directory
2021/04/30 08:37:43 DEBUG : test1: Removing directory
2021/04/30 08:37:43 DEBUG : 6 go routines active
felix@gemini:~$

If I were you I would put some test files inside the dirs and using min-age operator to simulate the scenario.

In my previous post, as you see it skips to scan empty directory just checking files and exclude them due to min-age restriction.

It would be due to min-age as that applies to files and would filter out the directories I believe.

Well, again it works for files not dirs; --rmdirs not working as it should be, at least in my case.

Right as I noted above, the age filters exclude out the directories as I've seen other posts on the same thing.

@ncw can chime in to validate as well as it's super easy to recreate.

What this command does

rclone delete remote:/backup --min-age 3d --drive-use-trash=false --rmdirs -v

Is effectively do

rclone lsl remote:/backup --min-age 3d --drive-use-trash=false --rmdirs -v

And then delete any directories you see listed in the above.

If you want to delete empty directories (recursively) then you can use rclone rmdirs

lsl doesn't recognize --rmdirs.

rclone delete remote:/backup --min-age 3d --drive-use-trash=false --rmdirs -v removes the content but cannot delete the directory.
I think the reason is --rmdirs checking the folder before deleting the files that is why it cannot remove the empty directory after wiping out the files.

My workaround is;
rclone delete remote:/backup --min-age 3d --drive-use-trash=false && rclone rmdirs remote:/backup --drive-use-trash=false
since delete --rmdirs doesn't work in my case.

1 Like

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