nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.52k stars 4.08k forks source link

Allow trashbin (and versions) to be restored on a per user basis from command line (`occ`) #30074

Open isdnfan opened 2 years ago

isdnfan commented 2 years ago

How to use GitHub

Is your feature request related to a problem? Please describe. often there are sync issues when desktop client removes or changes lot of files by mistake e.g.

desktop client #4016 desktop client #4035 desktop client #3444

As the sync is pretty fast and the error might be not obvious, this results in hundreds or thousands of deleted files or files existing as different versions.

Describe the solution you'd like Please add a possibility to manage this files from command line e.g. occ or other tool which allows user to perform mass recovery of files (and remove invalid file versions) after such issue.

Good starting point would be the server activity history where the user could review changed files and "undo" the action like restore previous version and delete new one or restore deleted files..

Describe alternatives you've considered If the problem affects multiple files in different folders the only alternative seems to be a server restore. as manual versions handling is impossible for more than couple of files..

cahogan commented 2 years ago

Hi, I had the same issue a couple of months ago and wrote a PR for it( #28935), which I'll link below. It's been reviewed but not released yet. I did use it to successfully restore thousands of deleted files, so hopefully it can help you as well.

isdnfan commented 2 years ago

Thank you for your comment @cahogan You PR is really great work but as far I understand the code this introduces Trashbin > RestoreAllFiles which is not exactly what I'm looking for. My intention would be to restore individual files from trashbin and recover specific versions. The idea was to script recovery once you identified faulty files e.g. by filtering for specific file attributes.

In my case I never hit a situation where all files enter the trashbin by mistake, it was only a subset - everything deleted before the issues was legit, so recovering all files would result in another error exactly the same as in #4016 when sync creates useless versions but only some versions need to be invalidated.. (but is a good option after malware attack)

isdnfan commented 2 years ago

18921 #20781

Grunthos commented 2 years ago

Yes, I agree. A per-file OOC command would be great. I have no problem getting file IDs from the DB or using paths and calling the script once per file.

Freundschaft commented 2 years ago

is mass recoery possible via webdav? https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/trashbin.html

thomas725 commented 2 years ago

I just found out that one of my nextcloud desktop clients had an incident two weeks ago where it deleted a random seeming selection of ~4k r files in about an hour (I wish I knew what that was about & hope that this won't happen again..)

I had hoped that this feature exists, but found out from this bug entry, that it doesn't.

So I took the suggestion by @Freundschaft to download an webdav xml, wrote a little program to generate a csv file containing filename & deletion-time: rust_code.txt

Opened that up in libreoffice calc, used the formula =A2/(24*60*60)+25569 to convert unix timestamp into libreoffice timestamps that can be displayed in a human readable format.

Then I copied the files I wanted to restore into kate (a texteditor) and used regex replace to generate curl move commands like:

curl -u user:password -X MOVE --header 'Destination:http://example.com/remote.php/dav/trashbin/USER/restore/filename' 'https://example.com/remote.php/dav/trashbin/USER/trash/filename'

Those take a few seconds each to process, so it will take a few hours till everything is back in it's place..