Google Drive API - Recovering the original folder for a file restored from trash before the original folder has been restored - google-drive-api

Scenario
There are many files in a Google (Team) Drive, all of which are nested in folders
All of these folders and their files are deleted by mistake.
In an attempt to recover the data, the Restore button on the Web UI is used
The Restore button in the Web UI does not seem to care about the order, and restores files before restoring the folders that contained them.
Thousands of files end up in the root directory of the drive since their folders "don't exist" when being restored from Trash.
What I need:
How can I recover the information about where the files used to reside, in order to patch this correctly?
What I tried:
Get all of the revisions for one of the files in question with Revisions: list and see there is only 1 result.
Get the revision information for that revision with Revisions: get
Realise that the revision information contains nothing about parents.
Get the file information with Files: get
Confirm that the head revision meta matches the only revision found in step 1
See that the file meta shows the parent is the root.
I can't find a way of determining what the original folder was for the trashed and incorrectly restored file.

After further investigation I don't think it is possible to recover the information about the previous parents from the Google Drive API v3.
However, if you are using Google Team Drive, as part of the G Suite, you should have access to the G Suite Admin SDK Reports API unless you are on a G Suite Basic account. With that you can use Activities: list with various filters to pull back the information about where the orphaned files came from.
I have published my solution here: Google Team Drive Orphaned File Restorer
This console application can pull a list of Google Drive file movements between two points in time, optionally filtered by the IP Address of the user who made the changes (i.e. restored the files from trash). It will then use that information to re-parent the files in question. You can do a dry run to see what the changes will be before you actually commit.

Related

Lifetime of a Google Apps script with no owner?

I have a Google Apps script that belonged to a former colleague. They have been offboarded and the script currently has No Owner. I am curious how long this GScript will exist without an owner assigned.
The user has been deleted since May and we have a backup.
Based on the fact that you can restore a user within the first 20 days of being deleted and a file can be restored within the first 25 days of being deleted (if the user still exist) I would say it will remain available 20 days. After that it will be permanently deleted and cannot be restored or transfer, I would suggest to make a copy of the file.
You can check these G Suite Administrator Help Center Articles to have more details about how Google manage deleted users and files.
Restore a recently deleted user
Restore deleted files or shared drives
Restore a deleted user's Drive files
UPDATE:
After checking the image well, I can see that the file is within a Shared Drive or "Team Drive" if that is the case according to "Store & share files with shared drives".
Members of a shared drive share ownership of any files and folders.
If someone leaves the shared drive, any files they added will stay.
You can still share files with a link or invite.
That means if the user is deleted (leaves the share drive) the file added will stay, so it will be forever. And the Shared Drive cannot be deleted if contains files, if someone wants to delete the Shared Drive they must delete the files first.
I just wanted to follow this up as I found a bug on Google Issue Tracker which shows that if a user is deleted while they own some scripts that are bound to Drive files, upon user deletion even if the Drive files are transferred to another user on the domain the owner doesn't change and the scripts can become inaccessable. Make sure that in the future all scripts are copied or saved in a shared Drive so that they can be accessed on user account deletion/migration.

User with edit privileges made files I own not viewable by me

I shared a folder containing files and subfolders with files with multiple users and gave them edit permissions. One users account has modified the viewing ability(?) of every file and subfolder they had access to. From my account when I open the top level folder I see it empty but I know these files are still there because I own the majority of them and my drive storage amount hasn't changed.
The user claims they have no idea how it happened so maybe that it was an app they unknowingly gave drive access to?
Is there any way I can fix this from the Google Drive web interface? I found Google Apps Scripts has access to the Drive API, should I find a script that can mass change the permissions?
Only the owner can delete the file.
The files were removed from the folder but were not deleted.
Therefore, they take up disk space.
To view files outside the folder, follow these steps:
https://drive.google.com/drive/search?q=is:unorganized%20owner:me
Excuse my bad English
Venca

Browse Files and folders uploaded on Google Drive

I'm writing from Italy (sorry for mistakes), my question is about GOOGLE DRIVE API and
I'm writing here because the G-Suite support wrote me to contact you, I'm not a programmer.
The big question is: how can I browse folders and files uploaded on my Google Drive Api?
I write you what apppened.
I wanted to use a backup program to save in a planned way files and folders an Google Drive.
I downloaded the program (Iperius Backup) and followed the instructions.
To understand on what I did, I paste the link of the instructions below:
http://www.iperiusbackup.net/en/backup-to-google-drive/
http://www.iperiusbackup.net/en/how-to-enable-google-drive-api-and-get-client-credentials/
I tried the software and everything worked.
So I opened Google Drive but the back-upped files weren't there.
Seen that there was something not clear, I have erased all the files on my Google Drive. I wanted to make sure that it was empty, hoping to erase also “hidden files”(...even if I thought it wouldn't have been so simple...)
To make sure that everything was erased (also “hidden files”), I tried to restore files from the backup software but unfortunately, the software worked well...the files were still there, somewhere...
This means that I have saved through the backup software files and folders on Google Drive “Api”, but I cannot manage them.
How can I have access to my space in Google Drive Api and erase all my files and folders that are still there?
Thank you in advance for the help,
best regards,
Stefano
To list all files in your drive, you can use Files: list.
This method accepts the q parameter, which is a search query
combining one or more search terms. For more information, see the
Search for Files and Team Drives guide.
You can use the Try it now or use the sample code given in a specific language you are using.
To delete/erase a file, use Files: delete.
Permanently deletes a file by ID. Skips the trash. The currently
authenticated user must own the file or be an organizer on the parent
for Team Drive files. Try it now or see an example.

DriveApp root Computers folder

Does anyone know how to easily access the Google Drive "Computers" folder that contains entries for each of a user's computers that was synced using the Google "Backup and Sync" application?
I've created a simple app script (more out of interest than anything else) which creates a Google Sheets document listing the contents of the current user's G-Drive. It starts with a call to DriveApp.getRootFolder(), and then lists and navigates the file tree from there. This all works fine, but it does not contain anything that is not a child of "My Drive", such as the Backup and Sync files stored under the "Computers" pseudo-root folder.
I've tried using DriveApp.getFoldersByName("Computers"), but that returned an iterator with zero items.
Not possible. You can only touch your regular "My Drive" (or team drive) files. No mention of that in Files: list.

How do I restore deleted documents from shared Google Drive folders?

A non-privileged Google Drive user has accidentally removed a large number of files from folders shared across an organisation. They do not have permission to delete the files entirely, because they are not the owner. However, users with edit permissions are able to remove a file from a shared folder. This returns the user to the owner, but seems to leave the file orphaned without a parent folder.
The files were owned by various different users.
How do I restore these files to their correct folders? The Google Drive Audit Log does not contain enough information to restore the folders correctly - the parent folder ID is not included with the "Remove from folder" event.
Google Drive is included in the Reports API of the Google Apps Admin SDK. It provides similar information to the Google Drive Audit Log, but with additional metadata. That includes the parent folder ID of files which were removed.
To restore the files you should first query the Reports API for files removed by the user in question over the relevant time period, using the Activities:list method.
Then you'll need to setup a Google Apps service account (which is a little confusing), to allow you to impersonate the owners of the documents that were removed.
Lastly, you can iterate over the event report for the removed files and use the Files: patch method in Google Drive REST API, to re-add the parent ID's to each of the files.
See Gist Using Google Drive API to restore files removed from shared folders
for example of the last step.