Solution for - Nextcloud on external HDD

So far I’ve been on various forums and sites because of the same problem "How do I move my Nextcloud data from /var/www/nextcloud/data to an external hard drive, for example ( /media/USB-Platte/nextcloud/data).

Many posts suggest that you create a folder on the external hard drive and then assign the values ​​(command line) “chown -R www-data:www-data /folder/data” to it, but as many people know, this doesn’t really work .

I literally spent 24 hours trying different variations and seeing what the problem was.

Here is my solution that I made for a standard nextcloud installation on an Ubuntu server 22.04 with mysql.

Step 1:
You need an external hard drive that should have a Linux format like EXT4 and not a windows format.
The disk should be mounted by Ubuntu right at startup, that’s important.

There you now create a folder, in my case that would be nextcloud/data.
Now open the console, navigate to the external hard drive directory and enter the following command “chown -R www-data:www-data /nextcloud/data/”

Step 2:
Now create a kind of link between the two folders, i.e. from /var/www/nextcloud/data to /media/USB-Platte/nextcloud/data (you have to look for the address of your folder path yourself).

This won’t work over symlink, so we’ll use a different method in this case.

The command for this is “sudo mount --bind /media/USB-Platte/nextcloud/data /var/www/nextcloud/data”

(sudo mount --bind /yourexternaldriver/nextcloud/data /var/www/nextcloud/data)

You bind the folder /var/www/nextcloud/data to /yourexternaldriver/nextcloud/data so that the folder is only there symbolically.

That worked for me so far, it’s similar to Docker, where you can also choose where you can bind a folder under the Volume category.

1 Like

Update:
Since the 2 folders are still linked after the restart, open the console and enter the following.

“sudo nano /etc/fstab”

here you have to enter the following at the very end:
“/media/yourexterndriverhdd /var/www/nextcloud/data none bind”

the connection is still available even after a restart

You drive foes not need to be EXT4. It only has to be a file system supported by Linux, BTRF or ZFS is working flawlessly aswell.

I keep asking myself why you need to link to the existing path and not just defining a new one with config.php?

Because it didn’t work for me and it looks like it didn’t work for many others if you wanted to outsource it to an external hard drive.

I just wanted to post a solution to others who have the same problem. :slight_smile:

I was able to move mine by simply stopping the web server, moving the data folder (keeping permissions and timestamps intact), changing the path in config.php, and starting it back up… have never had a problem related to it.

I think the vast majority of internet search cases where it didn’t work are because the person didn’t do something right or didn’t really understand paths or permissions.

I had done the same with me, i.e. stop the web server, entered the path change, set permissions as it should be and no success. I could also see from some contributions that they probably did the same thing without success, and I don’t really know why the normal method didn’t work.

In any case, I then tried tying, that was the only method for me that worked in the end.

Well as I said, I think in most cases there has been some mistake or oversight. Moving the data directory is functionally not that different from a migration where you only perform step 4. It must be done carefully with close attention to detail, but it’s not something that should break your system.