I've lost my data directory - what do I do?

Hi Folks,

I’ve had Nextcloud (possibly 12) set up on a Raspberry Pi for a while. 3 iphones and to macs connected to it.

A while (5 months) ago the external storage that had the data folder on it died :frowning:

I think I’d still be able to do a mysql dump of the database on the pi.

I want to spin up a VM version of nextcloud on a new NAS.

I’m hoping I can then restore the database to that version of nextcloud - but I won’t have any data folder to give it.

Will Nextcloud be able to recreate all the data from the files on the different devices?

any clues or pointers how to go about what i’m trying to do?

Cheers

David

If you have the data still elsewhere you can copy them back to the data directory (create one if neccessary) and run:

sudo -u $webserveruser php $nextcloud_docroot/occ files:scan --all

This will recreate the database entries.

To make it clear… the database alone will not get your files back. As @himbeere said, if you do have a copy of your old data directory, you can get those back, but not, if you do only have the database.

What I’m hoping you can tell me is that: I can use the database to recreate all the configuration of users, shares, calendars etc. And then the sync client can recreate all the data from the various devises’ local copies.

I don’t think I had anything on the nextcloud data storage that wasn’t stored on at least one device.

Thanks

David

What I’m hoping you can tell me is that: I can use the database to recreate all the configuration of users, shares, calendars etc. And then the sync client can recreate all the data from the various devises’ local copies.

I doubt this will work. Interesting idea though. What will work is taking the data from on of the clients, copy them to the server and run the mentioned command.

And should I put nextcloud in to maintenance mode as soon as I get it fired up. And keep it like that till I’ve copied all the data over and recreated the database for files?

Can anyone point me to the file structure I need to recreate in the data folder to position the files copied from devices?

Thanks

David

And should I put nextcloud in to maintenance mode as soon as I get it fired up. And keep it like that till I’ve copied all the data over and recreated the database for files?

Not really neccessary but wise i guess.

Can anyone point me to the file structure I need to recreate in the data folder to position the files copied from devices?

$datadirectory_as_configured_in_config.php/$user/

There i have:

cache contacts documents files files_trashbin files_versions gallery thumbnails uploads versions

Do you like puzzles? If yes, you can restore your NC, but it will involve a lot of fiddling with your database - especially with the oc_share table and the data re-synched to your user directories.

NC manages all it’s files through IDs in oc_filecache and the shares in oc_shares. The issue is, that the cliente may have downloaded the shared files and will upload them again, if you connect them to your new NC instance. This will be the main culprit, as this will break the shares in oc_share.

However, my approach to this would be roughly like this:

  • create a new NC instance and make sure the path to the user data is exactly as it has been before
  • have the user accounts sync their data - no frills, just files
  • now cross-reference the shares and try to delete the shared data from the user directories, before proceeding
  • stop your NC instance and replace the oc_filecache and oc_share from the salvaged database
  • run a file:scan —all