Nextcloud manual file recovery

From Newroco Tech Docs
Jump to navigationJump to search

Where a user has deleted a large quantity of files, or has managed to move a large quantity of files to another place (or where the deleted files system has been pushed past operational condition by sheer quantity of deleted files) a manual recovery might be required. The same process can also be used for large-scale import of files from another store.

File recovery

Starting point: knowing where the files should be and where they currently are.

On the Nextcloud front end server, navigate to the Nextcloud storage directory. In smaller installations this is likely "data" under


but can also be outside the main Nextcloud directory. When not sure you can easily check with

grep data /var/www/nextcloud/config/config.php

(or wherever your installation's config.php file is stored) which should return a line like

'datadirectory' => '/var/myncstore/data'

. Once in the data directory you can either go straight to the location the files should be if you know the path (as you normally would if the files are in a user's area), or if it is in a group folder first determine the group folder's number using

sudo -u www-data php /var/www/nextcloud/occ groupfolder:list

NB groupfolders along with its trash folder are under the directory __groupfolders. Next check the files to be restored are where they are believed to be; for a file or folder deleted from a groupfolder that will be in

__groupfolders/trash/<the groupfolder number>/rest/of/path

, for one deleted from a user's folder it will be in

. Once the files or folders are located, copy them using mv to the desired location, removing the "version" suffix as needed (this is often easier done after the move if multiple files are being moved). Once the files are back where they should be, the database needs to be updated with their existence; this is done with

sudo -u www-data php /var/www/nextcloud/occ files:scan --path="/"

In the case of a user folder the path should be self-evident, and the username has to be that user's. For group folders you can use any username that has permission to the relevant groupfolder or subfolder, and /path/to/files is the whole path as the user would see it in the web UI e.g. /groupfolder/subdir/subdir. Once a user folder file recovery is complete you should "tidy" the trash by running

sudo -u www-data php /var/www/nextcloud/occ files:scan --path="/"

. There's not currently an equivalent for groupfolders, and that cleanup has to be done manually.

File import

Follow the steps as above, just need to also

  • copy the files in from the existing store using scp, rsync, wget or some other method as suits
  • check the file storage permissions and ownership match those of the rest of files before running the files:scan step.