Nextcloud - Full Data Loss

I set up nextcloud on an older i5 laptop using an external usb harddrive to test and become familiar with the environment.

The other day I completed setup. Created admin and one (1) user.

Moved the data folder to the external hard drive

Created folders in nextcloud and uploaded some files to that folder.

Created a sync_test folder and synced a folder from my computer to that folder in nextcloud.

Shared folders with a group so the regular user can view.

Verified via ssh that folders and files were being written to the external drive

This morning logged via ssh and everything in the data folder is gone except a folder labeled: appdata_oc3s442i4vbc

Nextcloud opens to the: Your data directory is invalid. No .ocdata file found.

The config.php file still points to my updated folder structure.

I’m not sure what happened to the folders on the drive, which is formatted in ext4.

Below are the steps I took from start to finish to set up the environment.

Any help is greatly appreciated.

Install ubuntu 22.04 desktop - did this for the interface for personal ease and the automount feature.

*1. Update and upgrade
2. * Install openssh-server
3. * Sudo snap install nextcloud
4. * sudo ufw allow 80/tcp
5. * sudo ufw allow 443/tcp
6. * Log into nextcloud -create admin - enable external drive app
7. * Sudo snap stop nextcloud
8. * sudo snap connect nextcloud:removeable-media
9. * sudo mkdir /media/datadisk
10. * sudo mkfs.ext4 -j -L DataDisk /dev/sdb
11. * sudo blkid /dev/sdb - grab uuid
12. * sudo nano /etc/fstab - add: /dev/disk/by-uuid/4006fe68-879a-41ed-b4da-cc0e6bc6b4bb /media/datadisk auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=NewHDD 0 0
13. * sudo mount -a
14. * sudo mv /var/snap/nextcloud/common/nextcloud/data /media/datadisk/ncdata
15. * sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php - change datadirectory to: /media/datadisk/ncdata
16. * sudo chown -R root:root /media/datadisk/ncdata
17. * sudo chmod 0770 /media/datadisk/ncdata
18. * sudo snap start nextcloud

Now only the folder structure : /media/datadisk/ncdata exists with the subfolder appdata_oc3s442i4vbc

Thanks for any help as to what I may have done.

Update. I was able to use extundelete /dev/sdb --restore-all and retrieve all files and nextcloud is up and running again. However, I am still curious how they were deleted in the first place.
Thank you

Maybe you could elaborate on exact steps you took? Moving the data folder is a major change post-install.

Thanks for the reply. Steps 9 through 17 are how I moved the data folder. Step 14 is the actual moving of data. Then I altered the config.php and updated the permissions for the new destination. It worked great until it vanished.

Update. Same thing happened. Left it unattended. Came back. Couldn’t log in. Data folder is missing. I’m going to install it and leave the data folder on the internal drive and see if I get the same results.

Could you find any hint in the syslog between leaving and coming back?
Maybe your installation cannot not handle the external drive, if it went into sleep-mode.

I’m not sure about the snap version, but for other versions, the data folder must be owned by www-data:www-data and permission 750 for folders and 640 for files. Were they owned by root originally on yours?

I am not sure. I followed directions from another user who was very helpful in setting it up. Originally I wanted to have everything on an external drive. Not using the external drive plugin on nextcloud. But I couldn’t get it to work with an ntfs formatted drive, so I had to format it ext4, and I followed that user’s directions which included having root own it and a permissions of 0770. I can installing it again and changing the ownership and permissions as you have shown.
I’d really like doing that and have it ntfs formatted. But I’m not sure if that is asking too much.
Thank you

I would not give any further thought to hosting it on a NTFS formatted disk. That’s not going to do anything but cause you problems.

I assume the reason you want that is so you can directly access/modify Nextcloud’s data folder. This is also not recommended unless absolutely necessary.

It is mostly to have the folder/file sharing and creation functionality of the interface and not rely on the external storage app as much. Plus, in worst case scenario, I can grab the external drive in an emergency or for preloading of data, plug it into my windows machine and view/manipulate the saved data. e.g. documents, photos, etc.
Windows doesn’t like ext4. Can’t we all just get along. :slight_smile:
Thanks for your help

Windows does not like ext4, and servers does no like external drives. I used few years ago similar setup but with ext4 and few times due to some usb issues or something lost all data… So, I moved to more native and robust solution. Any way, there is also something to do after you move your data, there is a big topic about it: HowTo: Change / Move data directory after installation
And here discussion about snap user: External storage (Local) NC (snap) -- user www-data or root?

I’ve spent hours and hours in moving data folder from one drive to another although both are interna, later discovered that the destination drive Was NTFS formatted which could not accept either the Perkussion or the ownership of www-data (for get which one Was rejected).
stay away from NTFS when moving data folder.

Five things to prevent this in the future:

  1. Take automated backups of your data in regular intervals

  2. Take a manual backup of your data before you start a major file migration process

  3. Copy your data to the new location by using cp or rsync instead of moving it

  4. Delete the data at the source only when you are sure that the migration actually worked.

  5. Do not use NTFS

Or better:
5. Only use Linux file systems

(because VFAT is a “Do not use NTFS” file system, too :wink: )

1 Like