HowTo: Change / Move data directory after installation

Strange that (only?) the shares were lost. I wonder if some metadata is associated to the storage index as well. So Nextcloud adds the required new storage to the database by itself, but it is a new row while the old one with related index remains (invalid).

Did you do any changes to the files/shares etc since you moved the data? As when we change the storages table now, while old shares may be recovered, new shares may be lost. The new storages entry would need to be removed to avoid a duplication. The following query will give an overview:

select * from nextcloud.oc_storages;

yes i think that metadatas are affected as well…

files have been changed since then… but we have not created any new shares… and if anyone created new shares it is not a problem if they are lost afterwards…

in oc_storages i have the old storages at the top /nextclouddata and three new storages at the bottom /mnt/nextclouddata/nextclouddata & /mnt/nextclouddata/nextcouddata (typo…) & /mnt/nextclouddata

our new datadirectory is /mnt/nextclouddata/nextclouddata

Okay (after enabling maintenance mode, of course!), first you need to remove the new row, to avoid a duplicate, then replace the old entry:

remove from nextcloud.oc_storages where id='local::/mnt/nextclouddata/nextclouddata/';
update nextcloud.oc_storages set id='local::/mnt/nextclouddata/nextclouddata/' where id='local::/nextclouddata/';

And of course you can remove the additional two entries, if those are not used (anymore):

remove from nextcloud.oc_storages where id='local::/mnt/nextclouddata/nextcouddata/';
remove from nextcloud.oc_storages where id='local::/mnt/nextclouddata/';

Btw, every query should have an output as result, indicating that 1 row was affected, so you know it worked as expected.

Let’s see if that helps. Would be a strong argument then to fix the official migration documentation, or otherwise having a review into the code whether shares should be valid for a specific storage entry only or not.

1 Like

Maybe I just don’t get it and this might be some newb issue, so please correct me. But there are like tons of guides how to move data directory after installation. And there is always mentioned it would be a great idea to choose a suitable location during installation…But there is no reachable information about how to configure a non default data directory during installation…Think this is the largest issue in the nextcloud documentation.

It is one of the things you can select when you connect to the web interface the first time, where you choose the admin account name, enter the database credentials etc. Should be hard to overlook, actually :grinning_face_with_smiling_eyes: .

1 Like

looking through the official admin guide it doesn’t take ages to find the screenshot I referenced in this post

depending o your (automated) installation method you might not hit this screen - but I bet all of the (good) installation guides point you to the setting where you can change the data directory…

1 Like

Thank you @MichaIng for this thread, it’s incredibly helpful.

I am currently trying to implement Solution 1, but the copying is taking forever and I wanted to ask if that’s normal.

I run NC21 in a Linux Ubuntu VM (VMWare Fusion) inside a powerful Mac Pro. I am trying to move my nextcloud-data directory from /var/www/nextcloud-data which is on my limited hdd space on that vm to a newly created share on my Synology NAS in my LAN which I mounted in /mnt/nextcloud-data. I also edited /etc/fstab for automount after reboot.

The problem that I am seeing is that when I get to step 2 cp -a /var/www/nextcloud-data/. /mnt/nextcloud-data it takes forever to process; like many many hours.

So I cancelled the cp process by doing ctrl-c and tried copying the files instead via the Files app in Ubuntu GUI, and noticed it just wants to take an ENORMOUS amount of time to copy and paste the files into the newly mounted folder.

In the command line, after I type the cp -a command, it doesn’t give me any idea of how much longer it will take, whereas in the Files app in Ubuntu I can see how much longer is left (many many hours). Nevertheless I don’t know how/if I can replicate the cp -a option when copying via the Files app gui. Is it possible to do that?

Do you know if there’s another faster method of correctly copying the files over? Maybe tar? I wouldn’t know how to replicate the cp -a option in tar, if it’s even possible.

Any help is greatly appreciated.

Thanks,

Of course it depends on the storage read/write speeds, the amount of data and when copying to the network drive, the limiting factor most likely is network transfer speed. So yes, I’d say it is pretty much expected. You can test whether its faster when copying things onto a physical drive and form there to the NAS.

Compression most likely does not speed up the whole process as then the compression takes much time and the decompression at the target. If you deal with large amount of data, things will take their time, but luckily you don’t need to keep attending the copy process, just leave it in background and check back once in a while.

That’s the thing that strikes really odd. I have Gigabit LAN and the Mac Pro running the VM is connected via ethernet cable to the router, which itself is connected via ethernet cable to the Synology NAS, so I should be maxing out my transfer speed which should be limited by the Mac Pro’s SSD read speed (fast), and the NAS’s write speed (around 120 MB/s or 960 Mbps). In real life I am able to transfer from the Ubuntu VM to the NAS at around ~45 MB/s.

Instead the transfer speeds I am seeing are less than 1 Mbps, so in the Kbps range which is pretty ridiculous.

Reasons may be various, including transfer protocol and the filesystem of the servers network share. But since this is not really related to this thread, not even to Nextcloud, I suggest to open a new one about this, probably on another community platform when you can replicate by mounting that share on another client system.

Hello, I just started doing the first method, but now I have no clue what to do.
For the “mysqldump -u -p > /path/to/dbdump/dump.sql” command:
what is the path I need?

You don’t “need” any path, choose where you want to store the database backup. If unsure, the home directory is probably easiest to find it again quickly:

mysqldump -uroot -p > ~/dump.sql

respectively -u<username> with whichever user you used to initially create the database.

Okay! This post dates back some years, but if you are new to your own nextcloud on your homeserver it is still actual.
I installed nextcloud via snap. The data directory in the /var/snap/nextcloud/current/nextcloud/config/config.php is located here: 'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',.
This space runs out very quickly because it is with the ubuntu server on a ssd. The datadirectory should be on one of the HDDs in the server.
I read all and hopefully made a backup of the config.php and copied and chmod all the files from the /var/snap… datadirectory.
There is still an error “Your data directory is invalid Ensure there is a file called “.ocdata” in the root of the data directory.” on the webpage. To make it clear here is the output of my “new” datadirectory, which I named in the config.php 'datadirectory' => '/DATA/nextcloud/data',

root@mk-server:/DATA/nextcloud/data# dir -la
total 20
drwxrwxrwx 4 www-data www-data 4096 Jan 16 16:57 .
drwxrwxrwx 3 root     root     4096 Jan  9 19:36 ..
drwxr-xr-x 8 www-data www-data 4096 Jan 16 16:57 appdata_ID
-rw-r--r-- 1 www-data www-data  542 Jan 16 16:57 .htaccess
-rw-r--r-- 1 www-data www-data    0 Jan 16 16:57 index.html
drwxr-xr-x 4 www-data www-data 4096 Jan 16 16:57 manfred
-rw-r--r-- 1 www-data www-data    0 Jan 16 16:57 .ocdata

Why is there not a button in the Dashboard of the nextcloud page for the admin to change the Datadirectory?

Thanks in advance for any replies.
Manfred

Did you see the note about appliances at the top of the post? For the Nextcloud Snap appliance, follow the guide provided here: Change data directory to use another disk partition ¡ nextcloud-snap/nextcloud-snap Wiki ¡ GitHub

Thank you for the link.
I went on two ways:
First, when I posted here first I have installed nextcloud along this manual: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-nextcloud-on-ubuntu-20-04-de
Therefore I used the second way:

If you have already created an admin user

I ended up with the error : There is no .ocdata …
I tried different chmod and chown, starting and restarting snap nextcloud but the missing .ocdata did not disappear.

Because I was at the start there was nothing in the database yet so I sudo snap remove --purge nextcloud and deleted the data directory and the var/snap/nextcloud/ directory.

I did again sudo snap install nextcloud and followed the step one

If you just installed the snap, and haven’t created an admin user yet

I think the database is now located on the harddrive but I cannot login !

There are 27 issues on the github wiki: https://github.com/nextcloud-snap/nextcloud-snap/wiki/Change-data-directory-to-use-another-disk-partition#if-you-have-already-created-an-admin-user
and both my encountered errors are listed - this is frustrating!

The major problem is: I told my wife that we will have our own cloud to automatically save photos from the smartphone - How do I explain that I am wrong?

Manfred :sob:

The following seems to be a workaround:

ln -s /DATA/nextcloud/data /var/snap/nextcloud/common/nextcloud/data

But I have no experience with the Nextcloud Snap. @kyrofa could you have a look? There are indeed related reports at GitHub: Issues ¡ nextcloud-snap/nextcloud-snap ¡ GitHub

No, that won’t work.

You need to read that wiki article again. The very first paragraph:

The partition you want to use must be mounted somewhere in /media/ or /mnt/. These are the only locations the snap can access under confinement with the removable-media plug. Connect the removable-media plug as mentioned in the README in order to grant the snap permission to access external drives.

1 Like

late night:
next try and failed:
new sudo install nextcloud
changed the datadirectory to /mnt/DATA/nextcloud/data
the mount is fixed in fstab
now a new error appears:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

This is more than annoying !

I really cannot use nextcloud on my ssd. It is fast but too small for thousands of photos.

See in the morning!

Did you also connect the removable-media plug?

1 Like
snap connections nextcloud
Interface        Plug                       Slot           Notes
network          nextcloud:network          :network       -
network-bind     nextcloud:network-bind     :network-bind  -
network-observe  nextcloud:network-observe  -              -
removable-media  nextcloud:removable-media  -              -

shouldn’t there be an entry in Slot?