Empty Google Drive Trash

Just wanted to share my experience with emptying my google drive trash. Google's UI method to emptying trash is awful and extremely lacking, especially for the kind of people who use rclone.

The cleanup command was implemented into rclone to help. It basically uses the drive DELETE api command, which can be demoed here: https://developers.google.com/drive/api/v2/reference/files/emptyTrash?apix=true#try-it

I used the command, and it kinda worked, but even Nick (rclone's developer) has commented on other posts on this forum about how no-one really knows what's going on or why it sometimes doesn't work. For example, I tried the DELETE command directly in google's developer portal (link above) and the trash did not empty. Same with the the cleanup command. It's not the fault of rclone, it's Google's bad implementation of a simple delete idea.

But, I did find a solution that worked for me (be careful, however, as you can use a lot of API requests and get rate limited.) Use your own secret/key and I would recommend using a separate secret/key/project from the one you use for your production rclone setup.

Here's the command to run (add --dry-run to the first run to verify everything first so you know what you're deleting)
rclone delete gdrive-root: --drive-trashed-only --drive-use-trash=false --verbose=2 --fast-list

gdrive-root: a custom remote that has it's own client/key and does not have a folder id (runs on the root of the google drive)

--drive-trashed-only: This is absolutely crucial. It interacts with only the files in the trash in the same folder structure as it was when it was deleted from the drive.

--drive-use-trash=false: Also critical, as it doesn't use the drive trash when you delete the files. By default, a google drive remote will send deleted files to the google drive trash. We obviously want to empty the trash, so the false flag will bypass this default option.

--fast-list: this build a list of the files in memory. It uses less transactions (good for API usage) but it uses a little more memory.

--verbose=2: prints a verbose output of the operation, useful for keeping a visual eye on the progress

After running this, I empty 3tb of data that was just junk. I hope this helps someone who needs to empty their trash.

You can just use:

rclone cleanup remote:

https://rclone.org/commands/rclone_cleanup/

As mentioned, I do use it, but after running the command on cron jobs for almost a week, my drive trash was still massive, with thousands of files. It only removed about 2% of my trash after a week. But, after running the command in my post, I deleted the 98% in about 2 minutes.

Edit: To further clarify my original post, the inability to empty the trash via the cleanup/delete API command is not rclone's fault. I followed Google's instruction set on the developer portal. It completed with a good response, but all the files remained. So it's definitely not rclone's fault, as the problem is repeatable outside of rclone. My command posted above is more of a workaround, simply enumerating and deleting files while bypassing the drive files.

I think the issue might be more related to running it multiple times maybe?

I cleaned a few thousand files in 5 minutes as I checked back on it.

Are you using a team drive or regular drive?

Regular. And the interval was daily.

For me, rclone cleapup has always worked eventually but has taken some time (hours)! I typically just run it once then wait.

I haven't deleted that much data though.

@ncw, I figured that has to do with it. I just got impatient :slight_smile: and I gave this a shot. Worked quickly and effectively. Do you think you could create a --force-cleanup flag for the cleanup command? So something like this:

rclone cleanup gdrive: --force-cleanup

If the forced flag is used, it flips the cleanup command to a delete command with the trash options. So basically a shortcut.

That's a great idea. Can you tag a new issue on github for it?

1 Like

added issue #3964