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

**URL:** <https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530>\
**Category:** ℹ️ Support\
**Created:** [October 6, 2018, 10:14pm UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530 "2018-10-06T22:14:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidjeanneret](https://help.nextcloud.com/letter_avatar/davidjeanneret/32/6_22734026db12803ebb3e059622ac3534.png) [@davidjeanneret](https://help.nextcloud.com/u/davidjeanneret)\
**Post date:** [October 6, 2018, 10:14pm UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/1 "2018-10-06T22:14:43Z")

</div>

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 ☹

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

---

<div class="post-metadata">

**Author:** ![himbeere](https://help.nextcloud.com/letter_avatar/himbeere/32/6_22734026db12803ebb3e059622ac3534.png) [@himbeere](https://help.nextcloud.com/u/himbeere)\
**Post date:** [October 7, 2018, 7:01am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/2 "2018-10-07T07:01:24Z")

</div>

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

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

```

This will recreate the database entries.

---

<div class="post-metadata">

**Author:** ![budy](https://help.nextcloud.com/user_avatar/help.nextcloud.com/budy/32/697_2.png) [@budy](https://help.nextcloud.com/u/budy)\
**Post date:** [October 7, 2018, 9:44am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/3 "2018-10-07T09:44:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davidjeanneret](https://help.nextcloud.com/letter_avatar/davidjeanneret/32/6_22734026db12803ebb3e059622ac3534.png) [@davidjeanneret](https://help.nextcloud.com/u/davidjeanneret)\
**Post date:** [October 7, 2018, 10:27am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/4 "2018-10-07T10:27:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![himbeere](https://help.nextcloud.com/letter_avatar/himbeere/32/6_22734026db12803ebb3e059622ac3534.png) [@himbeere](https://help.nextcloud.com/u/himbeere)\
**Post date:** [October 7, 2018, 10:32am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/5 "2018-10-07T10:32:52Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![davidjeanneret](https://help.nextcloud.com/letter_avatar/davidjeanneret/32/6_22734026db12803ebb3e059622ac3534.png) [@davidjeanneret](https://help.nextcloud.com/u/davidjeanneret)\
**Post date:** [October 7, 2018, 10:56am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/6 "2018-10-07T10:56:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![himbeere](https://help.nextcloud.com/letter_avatar/himbeere/32/6_22734026db12803ebb3e059622ac3534.png) [@himbeere](https://help.nextcloud.com/u/himbeere)\
**Post date:** [October 7, 2018, 11:12am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/7 "2018-10-07T11:12:28Z")

</div>

> 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`

---

<div class="post-metadata">

**Author:** ![budy](https://help.nextcloud.com/user_avatar/help.nextcloud.com/budy/32/697_2.png) [@budy](https://help.nextcloud.com/u/budy)\
**Post date:** [October 7, 2018, 1:17pm UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/8 "2018-10-07T13:17:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 4, 2024, 7:57am UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/9 "2024-12-04T07:57:28Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 9, 2024, 3:23pm UTC](https://help.nextcloud.com/t/ive-lost-my-data-directory-what-do-i-do/38530/10 "2024-12-09T15:23:43Z")

</div>


