Google Drive - Untrash based on Trashed Date

What is the problem you are having with rclone?

I am trying to restore files from Google Drive's trash folder based on the date it was deleted.

When browsing the Trash folder in the browser, there is a column for "Trashed Date".

I am wondering if rclone is capable of Untrashing files using "Trashed Date" as criteria.

I know the date range of when I deleted the files, so being able to restore files based on "Trashed Date" would be great.

Some preliminary searching yielded the command, but not much documentation available.
rclone backend untrash DrivePath:

While doing some file cleaning on a mounted Google Drive, I accidentally deleted several thousand files, due to a misplaced asterisk (e.g. instead of rm prefix*, I entered rm prefix *). Thankfully, Drive moves deleted files to a Trash folder by default.
However, trying to Restore several thousand small files through browser is a nightmare, the endless scrolling UI is too clunky and slow.

Run the command 'rclone version' and share the full output of the command.

rclone v1.62.2

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)

I've had a quick look at
rclone backend untrash Drive:
but there doesn't seem to be much documentation out there to see if using "Trashed Date" as a criteria is possible.

I also tried to see what metadata might be available using:
rclone lsjson Drive: --drive-trashed-only
but it seems lsjson doesn't seem to work with the --drive-trashed-only option. It only returns the top-level directory structure.

Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

Not Applicable

A log from the command that you were trying to run with the -vv flag

Not Applicable. I'm asking if a feature is available, rather than reporting a bug.


welcome to the forum,

there is a forum topic about that.

could try rclone lsf and rclone lsl

the problem is that rclone backend untrash works on directories, not files..

from my quick testing, untrash not allow filtering. that needs to be confirmed.

tho should be ways to script around that.

Here you are a file with mtime 2019-04-22T17:01:32.113Z deleted moment ago (GMT) at btime 2024-02-27T20:28:19.058Z

$ rclone lsf --format "pM" drive: --drive-trashed-only --files-only

to list all deleted files:

$ rclone lsf --format "pM" drive: --drive-trashed-only --files-only --recursive

So now you can play with metadata (see metadata filtering) or write simple script. Myself I would write some bash script (use jq to extract info you need) - as metadata filtering is not something I am familiar with.

All info you need is available.

You can create two remotes: gdrive and gdrive-trashed-only and move/copy files between them based on some criteria e.g. btime. You need two remotes as flag --drive-trashed-only will apply to both src and dst if used in rclone command line

One off task script does not have to be perfect, e.g. you can simply grep for all btime containing 2024-02-27 instead of dealing with date/time nightmare conversions.

list all deleted files (`--format "pM"`)
for every btime containing `2024-02-27`
      rclone copyto gdrive-trashed-only:p gdrive:p OR use `rclone backend untrash gdrive:p`

i had tried rclone lsf but the ouput is always empty.
and that same issue is mentioned at
lsf:same output as lsjson

so how did you get that file listed?

$ rclone lsf --format "pM" drive: --drive-trashed-only --files-only --recursive

does not list deleted files?

Maybe your deleted file was not in the root folder - but --recursive flag should reveal it anyway.

ok, i could not reproduce your first example.
rclone lsf --format "pM" drive: --drive-trashed-only --files-only
for that, i got nothing, but you got a file listed?

rclone lsf --format "pM" gdrive01: --drive-trashed-only --files-only

tho, your idea of using two remotes and --recursive, that does work, does list the files.
and with that, the OP can script it.

1 Like

I am sort of sure because of a file location. I put sample file in root - so it worked.


and if you crack it please share details - this definitely can be useful for others.

for your good idea to work, we need the trashed time, not the btime?

Oups - you are right. It is missing....

BTW I looked at google drive web UI - it is actually very easy to sort items by bin time and select multiple items.

Thanks for the fast & informative replies.

Some interesting discussion & good ideas here.

Unfortunately it seems we still don't know how to get the key piece of metadata, deleted time. It seems mtime doesn't change when a file is trashed.

If we had deleted time metadata, as @kapitainsky suggested, a simple script would do the job.

Question regarding the two remotes solution:

If I create two remotes of the same service (G Drive), e.g. drive and drive-trashed-only and move between them, does the data pass through my computer, or is everything done server-side?

If it needs to pass through client computer, it works for smaller file sizes, for larger files then network bottleneck may be an issue.

It should happen server side but to be sure add --server-side-across-configs

However as bin time is missing from metadata I think it is theoretical.

I made mistake thinking that btime is the right data.

Yes, sorting & viewing by trashed time is quite simple on Web UI

But in my case, there are several thousand files that need to be restored.

Listing the files is not a problem, but when I click restore - even doing 50-100 - causes browser memory to spike and the page freezes for a while. Then I have scroll down, let the UI load the next batch of files, then repeat.

Anyway, I did end up doing it manually, it took me about an hour :sweat_smile:

Thanks for the discussion guys.

1 Like

yes, no flag is required.

1 Like

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