HowTo: Change / Move data directory after installation

Should work fine, did this on my machine as well some time ago. However do a mysqldump first, just to be sure.

I followed solution 2 and it works fine. But, subsequently I’ve tried to install ElasticSearch full text search in my NC accordingly to this manual. But this ends up not in a working full text search but in:

pi@raspberrypi:~ $ sudo service elasticsearch start

pi@raspberrypi:~ $ sudo service elasticsearch status

● elasticsearch.service – LSB: Starts elasticsearch

Loaded: loaded (/etc/init.d/elasticsearch; generated; vendor preset: enabled)

Active: active (exited) since Wed 2019-04-24 13:07:26 BST; 40s ago

Docs: man:systemd-sysv-generator(8)

Process: 556 ExecStart=/etc/init.d/elasticsearch start (code=exited, status=0/SUCCESS)

CGroup: /system.slice/elasticsearch.service

Apr 24 13:07:26 raspberrypi systemd[1]: Starting LSB: Starts elasticsearch…

Apr 24 13:07:26 raspberrypi systemd[1]: Started LSB: Starts elasticsearch.

pi@raspberrypi:~ $ sudo -u www-data php /home/pi/usbdrive/html/occ fulltextsearch:index

In Index.php line 380:

failed platform test.

fulltextsearch:index [–output [OUTPUT]] [-r|–no-readline] [–] []

What am I wrong?

Please verify if elasticsearch follows symlinks by default or not. Just a guess in the blue, since this is the basic change that comes with solution 2 :wink:.

Hi, in the next days I will need to add a new disk to my server and with this will change my filesystem. After this my nextcloud_data folder (only this since the nextcloud system files are on a different drive) will have a new path. I read that changing the path is not recommended. Since all files in my nextcloud instance are synced to clients and I don’t need the previous version etc. I wonder if there is a way to reset (empty) the nextcloud data folder without the need to reinstall nextcloud? Meaning that for all users the folder is empty and filled with the data from the clients at the first sync. Similar to the first sync after a new installation.

You don’t run it on DietPi, do you? In case moving the dietpi_userdata with nextcloud_data inside can be done without any changes to Nextcloud.

However otherwise changing/moving your Nextcloud data dir via solution 1 (of this HowTo) requires an adjustment of the database in every case, with or without clearing the data. In fact clearing the data just means additional steps and risk. So no benefit/point in doing this IMO, only the risk that clients pull file removals instead of pushing them to server.

Whatever you do, do a full backup of your Nextcloud install dir and database. And cp -a/rsync the data (preserving timestamps) instead of moving them, so you have a backup in case any issue, corruption I/O error or such happens. And block/disconnect the server from clients access until you verified (e.g. accessing to web UI locally) that everything went well, before re-opening for client access.

1 Like

Isn’t it a better solution to mount the new storage in your nextcloud folder directly?

I have nextcloud/data as one mount and /nextcloud/data/appdata_oc56k88881p0f/preview as another. Works great and it makes it easier to backup nc and user data.

The whole idea of having it outside the Nextcloud install dir is the security aspect to have it outside of the webserver document root. And the effort for moving/backing up is nearly the same. I mean if you copy/sync one or two directories does not really make a difference, does not?

But generally moving data by mounting it to the old location is actually a “solution 3” as alternative to the symlink method. However I personally prefer to have the least amount of links/mounts/redirects possible to keep things simple and avoid unexpected surprises and such. So I always go with “solution 1” and tell Nextcloud directly where the final location is, in case of a mount inside /mnt. But that’s as well about personal taste and needs.

Ok, thanks. Then I will try solution 1. A backup of my data is available. Worst case means at the end reinstall nextcloud on the server.

How can I check afterwards that everything went fine. Is it sufficient to simple open some files in the WebUI or is there any better check/test?

If you can see your files and can write to them (or create new ones) then this should be sufficient as check.

A reinstall should never be required as long as you have your e.g. /var/www/nextcloud (or where you installed it) and the database dump (as mentioned/created through the HowTos steps) you can always revert to the previous stage. PHP, webserver, Redis server (in case you use it) and all this are not affected.

Hi @MichaIng,
Thank you very much for this thread! Very helpful :slight_smile:

After all the answers, I am a little bit lost regarding the actual operations to be done to move data directory (as there have been updates since, some of the commands are no longer required).
I have a “Tech and Me” Nextcloud VM. I understand that, even if Solution 1 is a little bit more risky, it’s the one you recommend (mainly for security reasons). Then, can I use Solution 1, described in the first post for the “Tech and Me” Nextcloud VM? or should I change / add / avoid some commands?

Thank you so much again!

Hey guys,

Just found this article:

If you are looking to add some more space on data directory on your Nextcloud “Tech and Me” VM, why not just add a new disk on the ZFS pool?

Jep exactly, the official VM already has the data dir located on a separate ZFS partition, thus there is really no need to change anything about this and it might even break the VM UI elements.

If required, one could either raise the drives size + ZFS partition or add a new drive to the ZFS pool as you mentioned. However AFAIK there is usually no need to make things more complicated with a second data drive, the VM platform should allow to increase the size of existing drives, if required? At least on VirtualBox and VMware this works quite well.

I added the hint to the initial post besides Snap/Docker/NCP appliances hint, many thanks for reporting! :slightly_smiling_face:.

1 Like

Please keep in mind after move your data folder - Files amount after moving of data directory is wrong (much bigger).

But also note that when following Solution 1, the doubled entry is avoided by this step:

update oc_storages set id='local::/new/path/to/data/' where id='local::/path/to/data/';

But aside from that obviously, having a look into this database table generally makes sense from time to time, when heavily changing data dir and/or external storages.

1 Like

hey I have try your tutorial but i have some probleme. First I don’t find the occ folder in my server second when i enter the first command the console display “php:comand not found”
(I have install nextcloud on the ubuntu server setup)

occ is not a folder, but a file, located in the root of your Nextcloud install dir, e.g. /var/www/nextcloud/occ.

Is the error message from php that it does not find the occ command, or is the php command itself not found (which seems to be the case based on error message)?
Please check which php if it gives any output. Assure that you have php-cli installed (which ships the command).

Which OS do you use? Sometimes the command is shipped with PHP version string inside, e.g. php7.3. It should be located in /usr/bin/ or /usr/local/bin/ depending on your install method. Or you run some system-wise search: find / -type f,l -name php


Is there also a step by step guide for Apache/PostgreSQL? Thanks!

Solution 2 works with postgres just the same way. Solution 1 should as well, since the SQL syntax is the same, AFAIK. Besides of course there is another command than mysqldump to create a database backup. pgsqldump? :wink:

Got it: Nextcloud Daten-Ordner verschieben (Apache, PostgreSQL)

Are these instructions still up to date for NC17 and NC18?
When looking at the official instructions on how to migrate to a different server (e.g.,, that page states about potential path changes:
“On the new system make sure to pick the appropriate locations. If you change any paths, make sure to adopt the paths in the Nextcloud config.php file”
However, it does not mention that the database needs to be adjusted. I would have assumed that I had to follow the steps mentioned for “Solution 1” in that case as well.

To me it feels like either this howto is outdated or the manual is incomplete. Thus, can someone provide an update on this issue and either
a) update this howto article with details for current NC versions (16-18) or
b) stimulate an update for the manual page mentioned above.