prasmussen / gdrive

Google Drive CLI Client
MIT License
8.99k stars 1.19k forks source link

Could not find parent of 0ByqE7lC_kho3SXFmTHF6TkxDajA (backup_31.sync.gz) #244

Open gabrielsors opened 7 years ago

gabrielsors commented 7 years ago

I use gdrive on multiple servers to upload backups of various types. And since December / 2016 I got the message below:

Starting sync...
Collecting local and remote file information...
Could not find parent of 0ByqE7lC_kho3SXFmTHF6TkxDajA (backup_31.sync.gz)

The strangest thing is that the files reported are files that have been uploaded for more than six months and since then are not accessed, below file info command:

/root/gdrive info 0ByqE7lC_kho3SXFmTHF6TkxDajA
Id: 0ByqE7lC_kho3SXFmTHF6TkxDajA
Name: backup_31.sync.gz
Path: backupdb/xxxxxxxx/2016/05/yyyy/backup_31.sync.gz
Mime: application/x-gzip
Size: 1.5 MB
Created: 2016-05-31 04:20:43
Modified: 2016-05-31 04:20:43
Md5sum: f48bd46c541f362598898586240c81ea
Shared: False
Parents: 0ByqE7lC_kho3a1RQaFFnZzNhYTA

In cases of file collision I am deleting the files with problem and I repeat the process of synchronization, but in this case I can not do because I do not have the original file that was sent.

Currently spool the process daily using sync upload only:

/root/gdrive sync upload --no-progress --keep-local /home/backupdb/ 0ByqE7lC_kho3ZHVCb3hCMXNRQXM

I use Sync to ensure that no backup is forgotten.

Looking at the source code, I have an extensive list of files and I realized that the logic fetches the parent folder from the file, can not this loop be caused by this problem? Any memory limitation for example?

Thank you!

mattpr commented 7 years ago

Another example of this issue...

The issue seems to come from listing all the remote files and trying to find the first parent path for each. https://github.com/prasmussen/gdrive/blob/master/drive/sync.go#L219

The file was already uploaded by gdrive in the past but it was moved into a different folder after the scripted gdrive upload.

gdrive info "fileId" does return result for the file in question as well as its parent. It is just the sync code that is having trouble.

One thing I noticed... gdrive info returns a ViewUrl of form: https://drive.google.com/a/[ga-domain] for the file in question, however for the parent it returns a ViewUrl of form https://drive.google.com/drive/ (ie without the GoogleApps domain). Not sure if it is relevant or just a difference between view urls for folders and files on google drive.

# ls -1 scanner_upload
auslage
other-documents
paid-invoices
unpaid-invoices

# ls -1 scanner_upload/paid-invoices/
2017-02-02 - Hotel Alte Post - Rechnung.pdf
2017-02-18 - Bahn - Bahncard Losch.pdf
2017-02-24 - BMW - Rückstand.pdf

# gdrive  --refresh-token "[token]" info "0B1HLIFeM7hsRY05xMGdIR3cyNm8"
Id: 0B1HLIFeM7hsRY05xMGdIR3cyNm8
Name: scanner_incoming
Path: scanner_incoming
Mime: application/vnd.google-apps.folder
Created: 2017-02-20 18:47:14
Modified: 2017-03-01 09:45:18
Shared: True
Parents: 0AFHLIFeM7hsRUk9PVA
ViewUrl: https://drive.google.com/drive/folders/0B1HLIFeM7hsRY05xMGdIR3cyNm8

# gdrive --refresh-token "[token]" sync upload "scanner_upload" "0B1HLIFeM7hsRY05xMGdIR3cyNm8"
Starting sync...
Collecting local and remote file information...
Could not find parent of 0B1HLIFeM7hsRMzNiWG5fY3RETGc (2017-02-24 - BMW - Rückstand.pdf)

# gdrive  --refresh-token "[token]" info "0B1HLIFeM7hsRMzNiWG5fY3RETGc"
Id: 0B1HLIFeM7hsRMzNiWG5fY3RETGc
Name: 2017-02-24 - BMW - Rückstand.pdf
Path: Rechnungsverwaltung 2017/RG Eingang/02 Februar 2017/2017-02-24 - BMW - Rückstand.pdf
Mime: application/pdf
Size: 865.1 KB
Created: 2017-03-01 09:11:23
Modified: 2017-03-01 09:11:23
Md5sum: 6bdc2625b56958278692026623c0543f
Shared: True
Parents: 0BylfOx0NAyx4UHdJVFJLUi1ZLU0
ViewUrl: https://drive.google.com/a/[ga-domain]/file/d/0B1HLIFeM7hsRMzNiWG5fY3RETGc/view?usp=drivesdk
DownloadUrl: https://drive.google.com/a/[ga-domain]/uc?id=0B1HLIFeM7hsRMzNiWG5fY3RETGc&export=download

# gdrive  --refresh-token "[token]" info "0BylfOx0NAyx4UHdJVFJLUi1ZLU0"
Id: 0BylfOx0NAyx4UHdJVFJLUi1ZLU0
Name: 02 Februar 2017
Path: Rechnungsverwaltung 2017/RG Eingang/02 Februar 2017
Mime: application/vnd.google-apps.folder
Created: 2017-01-04 16:02:58
Modified: 2017-01-04 16:02:58
Shared: True
Parents: 0BylfOx0NAyx4b0xDSzhGSWlMdm8
ViewUrl: https://drive.google.com/drive/folders/0BylfOx0NAyx4UHdJVFJLUi1ZLU0
gabrielsors commented 7 years ago

@mattpr , interesting, but this difference isn't because id "0BylfOx0NAyx4UHdJVFJLUi1ZLU0" is a folder and "0B1HLIFeM7hsRMzNiWG5fY3RETGc" is a file?

mattpr commented 7 years ago

@gabrielsors it could be. I ran a couple more tests and that hypothesis seems to hold.

My primary theory is that this relates to folder ownership and moving files into folders owned by other users.

Given the number of open issues I may just have to dust off my go and figure out why the referenced bit of code doesn't find that object id when gdrive info does find it. But this is a minor issue for me and so it might be a while before I get a chance.

NorbiPeti commented 7 years ago

After figuring the code out I think the issue is that the moved folder still has the "syncRootId" property set to the sync directory, but since it was moved from there, gdrive cannot find the moved folder in the sync folder - while the query reports the moved folder as well.

gdrive list --query "appProperties has {key='syncRootId' and value='<sync root dir id>'}" reports the moved folder and that query is used for getting the file list for the sync download as well. Since the moved folder's parent isn't in the sync directory, it's not picked up, therefore it can't find it.

j0e1in commented 7 years ago

Any update on this? Does this mean we can't move synced files to another folder?

carmenates09 commented 7 years ago

I have the same Issue, I need help.

`user@server:~/backups$ /home/user/backups/src/gdrive-linux-x64 sync upload /tmp/backups/201706021656/ ...my_google_folder_id...

Starting sync... Collecting local and remote file information... File ...google_folder_id... does not have exacly one parent`

The error become when I delete a folders inside my folder (my-id) on google drive, but I need delete folders on google drive (remote) and the gdrive continue sync.

Jose Carlos Ramos Carmenates

fabzo commented 7 years ago

I've run into a similar problem when manually creating a directory on google drive and moving an already synced folder into the newly created one.

It resulted in a hierarchy similar to this:

Which lead gdrive to report that it could not find the parent of folder3, since it was not obtained using the query mentioned by @NorbiPeti .

I created a little function that builds a list of all files in a given syncRoot and adds the syncRootId to all of them. Similarly it will set the syncRootId to "" on all other files that have it set but are not in the syncRoot.

See this branch comparison. I just hacked it together as a quick fix for myself. But maybe this could be helpful/interesting with a little bit of cleanup and testing.

Or maybe there is another way for gdrive to keep track of the syncDir files/folders? I have not yet worked with the google drive API apart from this little hack. But it seems that the syncRootId is used for efficiency reasons and is not strictly required?

The problem mentioned by @carmenates09 seems to have another cause and is not related to the misplaced syncRootId. As far as I understand...

Update: Well I would say further testing is indeed needed. As it seems that i missed something which resulted in some files no longer being in the sync root ;-)

NorbiPeti commented 7 years ago

@fabzo I'm getting Is '', but should be non existant or empty (with an empty ID) for each of my files outside the synced folder it looks like while applying the fix. Other than that it seems to work in my case as well. Thanks for posting it. 😛

tinti commented 6 years ago

Removing the file_cache.json file solved the problem for me.

Maybe the cache handler is missing some points.

astanet commented 6 years ago

I faced similar problem.

> gdrive.exe sync upload --delete-extraneous storage FOLDER

Starting sync...
Collecting local and remote file information...
File FILE_ID does not have exacly one parent

Deleting the file with problem fixed error. Thank you.

fnxnet commented 5 years ago

Same issue here. Somehow I can not even use --delete-extraneous as it keeps saying that the parent can not be found.

abneetwats24 commented 1 year ago

Please delete dangling objects by

gdrive delete 0ByqE7lC_kho3SXFmTHF6TkxDajA
gdrive sync upload  /home/backupdb/ 0ByqE7lC_kho3ZHVCb3hCMXNRQXM

You can write bash script to first check all dangling objects then run delete then do sync