Trash all Drive content for many users

218 views
Skip to first unread message

Pirooz Jolani

unread,
Mar 19, 2024, 9:23:18 AMMar 19
to GAM for Google Workspace
Hi all,
we are in the process of cleaning up storage and need to Trash (not purge) all Drive files from thousands of users.  I am running GAMADV-XTD3 6.71.15.  What would be the best way to do this?  Google has shared the below command to delete multiple files belonging to multiple users, but that's all the information I have.  Would someone be able to tell me if this will do the job and how to go about using this?

gam csv ./files_to_delete.csv gam user “~Owner” delete drivefile “~id” purge

Thank you in advance.

Pirooz

Ross Scroggs

unread,
Mar 19, 2024, 9:57:58 AMMar 19
to google-ap...@googlegroups.com
Pirooz,

I'm not clear, what's the point of putting thousands of users' files in the trash? Is it that you don't want them to be deleted(purged) for some period of time?
In GAM, delete is equivalent to trash; purge permanently deletes the file.

The command you were given will purge the files immediately.


Scroll to Method 3, use delete instead of purge if you want the files trashed.

Send me a Meet/Zoom invitation.

Ross

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/68a81022-b2cc-4203-920f-68d358e3b3f8n%40googlegroups.com.


--

Pirooz Jolani

unread,
Mar 19, 2024, 10:07:43 AMMar 19
to GAM for Google Workspace
Thank you, Ross.  Yes that is the ask, that we give these files 30 days just in the unlikely case that any are to be restored.  My question is, are we to do this one user at a time or is there an easier way to achieve this for the thousands that we need to do this for?

thanks,
Pirooz



Seth Rouggly

unread,
Apr 5, 2024, 5:54:50 PMApr 5
to GAM for Google Workspace
Pirooz,

We are working though the same type of situation and this is what I found, hopefully it is helpful to you as well.
The shot answer to your question is to drop the "purge" in the command as Ross indicated.
This should send the file to the trash without deleting them. (Test this in a test environment or test OU with restricted GAM permissions)
 I'm using "$" to indicate the beginning of the shell command
$ gam csv ./files_to_delete.csv gam user “~Owner” delete drivefile “~id”

Context and a more robust method:
Using the method below in testing, the drive files were sent to the trash. We emptied the trash and still had the capability to administratively recover deleted/emptied trash files before they are permanently deleted after that (about 25 days I think).
This gives a safety net over "purge" which makes the deleted files permanently deleted.


The Comments have instruction on how to use it with some helpful GAM commands that I think you are looking for:
    Usage:
    1: Get information for all files, if you don't want all users, replace all users with your user selection
         in the command below, e.g., ou /Students/Classof2019
        These fields are required: fields id,name,owners.emailaddress
        You can add additional fields that will be preserved in the output.
        $ gam config auto_batch_min 1 redirect csv ./UserFiles.csv multiprocess all users print filelist fields id,name,owners.emailaddress fullpath
        With an OU (For some reason I could not get it to work as described above):
        $ gam config auto_batch_min 1 redirect csv ./UserFiles.csv multiprocess ou "Testou" print filelist fields id,name,owners.emailaddress fullpath
    2: From that list of files, output a CSV file with the same headers as the input CSV file
        that lists the drive file Ids that are not in the selected top level folders
        $ python3 SelectiveDelete.py ./UserFiles.csv ./DeleteFiles.csv
    3: Inspect DeleteFiles.csv, verify that it makes sense and then proceed
    4: Delete the  files (There is a typo in the git repo on this line, "./DetelteFiles.csv" should be "./DeleteFiles.csv" )
        $ gam redirect stdout ./DeleteFiles.log multiprocess redirect stderr stdout csv ./DeleteFiles.csv gam user "~owners.0.emailAddress" delete drivefile "~id"

This was a good starting point for me and ended up writing commands (based on the above) to empty the trash too:
    Empty Trash:
    1: Get list of users to empty trash
        $ gam config auto_batch_min 1 redirect csv ./Users.csv multiprocess all users print users
        With OU (multiple OU's can be added, but should match above):
        $ gam config auto_batch_min 1 redirect csv ./Users.csv multiprocess ous "TestOU" print users
    2: Empty Trash for users
       $ gam redirect stdout ./TrashCan.log multiprocess redirect stderr stdout csv ./Users.csv gam user "~user" empty drivetrash

I'm sure this could be streamlined, but it's a good place to start and hopefully adds some context.
This has worked for us in our test environment, and we will be running this on production soon.

Hope this is helpful for you!
~Seth

Pirooz Jolani

unread,
Apr 7, 2024, 6:53:45 PMApr 7
to google-ap...@googlegroups.com
Thank you Seth for this comprehensive write-up.  Ross was kind enough to go through most of these with me on a Zoom call.  Here are some of the commands that I used that are similar to yours plus some additional information that could be helpful for others.

Create a CSV file "Users. csv" with the of the users to Trash their Drive content.  The column header should be "Owner".  The command below will create another CSV file "UserFiles.csv" with the document ID and other information of all files belonging to the uses in "Users. csv"
gam config num_threads 20 redirect csv ./UserFiles.csv multiprocess redirect stdout - multiprocess redirect stderr stdout csv Users.csv gam user "~Owner" print filelist my_top_items fields id,name,size,mimetype

The command below with Trash all files captured in "UserFiles.csv" and create a log file UserFiles.csvLog.txt
gam config num_threads 20 redirect stdout ./UserFiles.csvLog.txt multiprocess redirect stderr stdout csv UserFiles.csv gam user "~Owner" trash drivefile "~id"

At times after this step, some hung processes would never end and I would continue getting: "Waiting for X running processes to finish before terminating, wait limit unlimited seconds" which I would have to kill the process which meant some orphan documents could not be Trashed.

To get the Orphans files for users
gam config num_threads 20 redirect csv ./UserOrphanFiles.csv multiprocess redirect stdout - multiprocess redirect stderr stdout csv Users.csv gam user "~Owner" print filelist choose orphans depth 0 fields id,name,size,mimetype

To Trash the Orphan files
gam config num_threads 20 redirect stdout ./UserOrphanFilesLog.txt multiprocess redirect stderr stdout csv UserOrphanFiles.csv gam user "~Owner" trash drivefile "~id"

Thanks again,
Pirooz


You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/OwQZAi7k7-I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/d9b0e5df-ed10-48e0-a478-e8e34edd3620n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages