Is there a safe and reliable way to move data directory out of web root?

This should do the same job.

Coming from an otherwise default installation, would that user www-data?

ā€¦ or just the systems root user?

If default installation means apache webserver, it must be www-data as this it the default web user that is used by nextcloud to write your data. Nextcloud has thanks god no access to the root user ;).

I must have missed somethingā€¦I log in as root, cp the ā€¦/data folder to the new location, but when I run the chown command, it says ā€œoperation not permittedā€. Suggestions?

ā€¦ ā€¦ ā€¦ ā€¦

I have been struggling with this issue all week and finally came across this very useful thread. Thanks to all contributors. However, after going through the various items listed above in robertbā€™s posting of Sep '16 I still had the mentioned error :

Data directory (/etc/nextclouddata/nextcloud/data/) is invalid. Please check that the data directory contains a file ā€œ.ocdataā€ in its root.

I had learnt in other attempts that the nextcloud.conf has also to be modified by adding the new data directory path as follows (using robertbā€™s data directory as an example) :

php_admin_value open_basedir ā€œ/srv/http/:/dev/urandom:/tmp/:/usr/share/pear/:/usr/share/webapps/nextcloud/:/etc/webapps/:/etc/nextclouddata/nextcloud/data/ā€

So I tried adding my path and all is working again with a new directory path.

Hope this comment might help those using Nextcloud 11.

Note : I am running on Archlinux so the apache user is ā€œhttpā€ and not ā€œwww-dataā€

Running:
nextcloud 11.0.2-1
php 7.1.3-1
apache 2.4.25-1
mariadb 10.1.22-1
archlinux 4.10.6-1

Hi, I have the latest version of Nextcloud running on Raspbian. I tried to change the path of the data directory. I moved all /mnt/dietpi_userdata/nextcloud_data files to /mnt/myexternaldrive/nextcloud, then do chown -R www-data:www-data, changed settings in config.php and in oc_storage in the database.

I still get Data directory (/mnt/myexternaldrive/nextcloud) is invalid. Please check that the data directory contains a file ā€œ.ocdataā€ in its root.

I canā€™t find any nextcloud.conf. What may I do?

Thank you!

Unfortunately Iā€™m a total rookie when it comes to this. I got very lucky with some good advice.

Did you run the following?

chown -R www-data:www-data /mnt/myexternaldrive/nextcoud/data

If I had to guess, it sounds like your path to your data file is specified incorrectly. But again, my experience is minimal.

hi,

when re-attaching the external hard drive/usb, make sure you plug it in on the same port.

i had it configured in the fstab and when i plugged it into another port i couldnā€™t see a thing inside the HDD.

i hope this works for youā€¦ :slight_smile:

I have successfully configured nextcloud so that my data-folder is located on a external USB HDD.

Personally, I reinstalled nextcloud because moving the data-folder after installation is not officially supported.

I formatted my HDD as NTFS so the data would be accessible from other OSs and pasted the following last in /etc/fstab (remember to insert correct UUID):
UUID="[INSERT UUID]" /mnt/ekstern ntfs-3g defaults,auto,uid=33,gid=33,umask=077 0 0

Hope this helps.

I posted this on another thread a while back, but thought it could assist you.

Though it may not be supported as others have pointed out in many threads, I have yet to have an issues changing data directorys; I have changed the data directory many times on many different OwnCloud & NextCloud hosts just fine without any issues. These are the steps I take to move the data directory: (This only works if you have no data to move, as if this is a fresh install)

Run the following command in the Linux shell:

o sudo service apache2 stop

o sudo mkdir /media/user/your_hard_drive/nextcloud_data ā€œor whatever you want to call it?ā€ Remember the /media is your mount point or external hard drive.

o sudo chown -R www-data:www-data /media/user/your_hard_drive/nextcloud_data/

o sudo chmod -R 777 /media/user/your_hard_drive/nextcloud_data/

o sudo chown ā€“R www-data:www-data /media

o sudo nano /var/www/html/nextcloud/config/config.php

o Once you are in the config.php you need to change your data directory. Save file and exit.

o Sudo service apache2 start

Hope this helps you out.

~wclang

I have moved my data folder using the steps described by @wclang and at first sight everything seemed to be fine. However after a restart of my system I received an Internal Server Error right after the login, see ā€œhttps://help.nextcloud.com/t/13256ā€

One step that is missing but mentioned by the previous posts is to update the database table oc_storages. Also you should activate the maintenance mode inside config.php before you apply the changes.

One additional thing I had to do was to delete all the contents from the table oc_filecache. Afterwards I simply restarted Apache, deactivated maintenance mode and when I logged in to nextcloud, everything was working fine again.

For future reference folks, you can also just symlink from /var/www/data (or wherever you set it up initially) to your new location after moving everything. Iā€™m personally a fan of sudo rsync -avP as it preserves all files, permissions, ownership and shows progress as it goes, then deleting the original when Iā€™ve confirmed everything (including hidden files) has been copied over.

That way thereā€™s no need to update the DB and you wonā€™t be told thatā€™s unsupported.

3 Likes

I would add :
6: check the read/write permissions of the new folder (if created and not only moved, as suggested by @robertb )

I should of stated in my post that my process is for fresh builds only without any data in it, if you have data then following ā€œsireaā€ additional steps will be required. Thanks for pointing that out ā€œsireaā€ :slight_smile:

note th[quote=ā€œJasonBayton, post:4, topic:3642ā€]
Make sure no cron jobs are running
Stop apache
Move /data to the new location
Create a symlink from the original location to the new location
Ensure permissions are still correct
Restart apache
[/quote]

Note that you have to configure your webserver to respect that symlink, I believe not all do :smiley:

1 Like

Edited that in :slight_smile:

1 Like

I added a new 1TB virtual drive and moved the data directory in NextCloud 12.0.0 by doing the following:

Partition and mount new 1TB drive (standard disclaimer - if you donā€™t know what this does, donā€™t do it, you will likely lose data)

sudo mkfs.ext4 -G 4096 /dev/sdb
sudo blkid /dev/sdb
/dev/sdb: UUID=ā€œcopy ID listed hereā€ TYPE="ext4"
sudo mkdir /mnt/data
sudo nano etc/fstab

/mnt/data was on /dev/sdb

UUID=paste_UUID_here /mnt/data ext4 defaults 0 2

sudo mount -a
sudo chmod -Rf 777 /mnt/data

Now for the data move to fresh disk:
sudo systemctl stop apache2
sudo rsync -avP /var/www/nextcloud-data /mnt/data/
sudo nano /var/www/nextcloud/config/config.php
ā€™datadirectoryā€™ => ā€˜/mnt/data/nextcloud-data/ā€™,
sudo shutdown -r now

Seemed to work just fine.

this steps worked for me too. could it really be that easy?