Using webdav or plugin to restore a file that was deleted months ago

We are using owncloud server 10.15.2.

The last hurdle stopping us from fully switching from dropbox to owncloud is the ease at which dropbox can restore a deleted file.

Ultimate goal: Need guidance to find the best way to restore a file that was accidentally deleted an unknown amount of time ago. Thousands of files are deleted weekly. Deleted filename is known.

My idea was to writing a custom tool to filter deleted files by filename and then using the webdav api to restore the fileid. I am somewhat successful using the webdav trashbin api but am struggling to get the filename metadata if the fileid is in the trashbin.

I used curl to list the deleted files and extract their fileid

curl -u admin:password -H "Depth: 1" -H "Content-Type: text/xml" -X PROPFIND  "https://host/remote.php/dav/trash-bin/admin"

but running this to get the filename associated with the fileid fails

curl -u admin:password  --data "@meta-files.xml" -X PROPFIND "https://host/remote.php/dav/meta/<fileid>"

where meta-files.xml is

<?xml version="1.0"?>
<a:propfind xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns">
    <a:prop>
        <oc:meta-path-for-user/>
    </a:prop>
</a:propfind>

returns notfound exception unless I first manually restore the file using the web interface.

Ok, I am able to get the file list with file names using this curl command from here.

https://stackoverflow.com/questions/46211099/how-to-delete-file-in-trash-in-owncloud

curl -u admin:password -X GET  "https://host.com/index.php/apps/files_trashbin/ajax/list.php?dir=/"

i am having trouble undeleting though with this

curl -u admin:password  -X POST  --data "files=[\"/1.txt.d1753985601\"]&dir=/"   "https://host.com/index.php/apps/files_trashbin/ajax/undelete.php" 

returns {“data”:{“message”:“Token expired. Please reload page.”,“error”:“token_expired”},“status”:“error”}

must need to pass this token in the header. Any idea on how to get this token?

Found out how to get the token.

curl -u admin:password -c - -X GET ""https://host.com/index.php/apps/files/?dir=/"""

this will get a page that contains the requestToken as well as the session cookies.

You must pass the requestToken and session cookies in the header of the undelete curl command for it to work.

Thanks for the insight, always good to learn another way to do things. I do have backend access so it reassuring I can go that route if my solution starts to fail with large number of deleted files.

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