Mass restore files from recent version (or find all files with 0 length)

Hello,

I have NextCloud 15.0.11 on server, 2.6.4git client on Ubuntu 16.04 Desktop.

I have just met a problem with many files (gigabytes) somehow got zero length on server (during sync process - I was truing to make a backup copy on removable HDD drive connected to local computer) and after that some local copies were partially corrupted too during back sync. Luckily I can see zeroed files in their places on server and they also have non-zero version in version history, so I (I hope) can restore each one of them via web interface.

I have described the issue itself as bugreport here:

Files got zero length on server (and then started to turn local copy to zeros) during sync

Here I want to ask for help, how can I restore from this situation and get my files back and have some questions:

  1. Is there a way to make mass-restore all files to some specific version (for example, specified by date and time)? Preferably in semi-automatic mode (so I could see the whole list of files to revert before revert to confirm). “Recent changes” view does show too small number of files (looks like I have hundreds if not thousands files got zeroed to restore).

  2. If not, can I at least somehow make global search for files with specified size (exactly 0 bytes) to show them in one big list?

  3. My web interface did show about 302Gb used space (in low left corner) in the morning and now it shows 298Gb - after the zeroing process (I have put it on pause) (the whole disk is about 1Tb). I have read about versioning policy, I have enough free space, so I hope the versions were not deleted (as I checked random files - they are on the place). But I am a bit worried by this reduction of displayed occupied space - does it show occupied space without space taken by version history of files?

  4. Also (hope this is not my case) would not just zeroed, but deleted files have their older versions too?

thanks’

I’m not aware about a gui function which you can use for this but it might be possible to write a batch script which you run on the console to do the job for you. It might be possible to use the find command to identify 0-length files, look for matches under “/data/user/files_versions” and copy over existing files.

Aunt G. knows the answer: Linux Tips: find all files of a particular size · MD/Blog

Ok, I have executed:

find /var/www/nextcloud/ -type f -size 0k -exec ls -lh {} \; > nc-zeros.txt

and got file with about 4700 rows (one row per file). At least I can now see all of them, thank you :slight_smile:

look for matches under “/data/ user /files_versions” and copy over existing files.

thank’s for this tip, I will give it a try

Also ran into this issue, caused by the Workflow OCR erroring but happily thrashing any and all PDF files it found.

On the shell:

# find /opt/nextcloud/data/user/files/ -size 0 | grep pdf | less

will output a list of files to standard output. Once you have it you can then use the web GUI to find and restore files that got corrupted.

We did find the old versioned files in /opt/nextcloud/data/user/files_versions/ but available documentation is not at all clear on how you could restore them. Sure you could move them back to their original locations and run occ files:scan but given this happened in a production server we were unwilling to see what happened. We also ended up restoring from backup.