14

I installed nextcloud on my raspberrypi 3 using this link. Everything is working pretty well except I don't like the UX of having all the extra storage space coming from the "External Storage" add-in, since it means that everyone now has to know to put all of their files in a designated folder.

It seems like I should just be able to tell nextcloud to use the external harddrive as the data-directory location (without the external storage add-in) and all will be well and good... and it seems like in theory that works fine. But, since it's installed as a snap, it seems like the snap doesn't have access to that part of my filesystem and thus it doesn't work.

I was wondering if anyone had any suggestions. Should I mount the harddrive inside the snap's writable area? Is it possible to give the snap access to the harddrive?

Matt
  • 143

2 Answers2

22

A bug was logged against the Nextloud snap for this issue, with the solution given here. It's now a wiki entry as well.

To quickly summarize here: you're right, this should be possible, and it is. However, by default the Nextcloud snap doesn't have permission to access removable media (as mentioned in its README).

So, the steps given are:

  1. Connect the removable-media plug: sudo snap connect nextcloud:removable-media.
  2. Connecting that interface gives Nextcloud permission to access things in /media/, so you can edit /var/snap/nextcloud/current/nextcloud/config/config.php and make sure the datadirectory is pointing to the right place.
  3. Disable the snap: sudo snap disable nextcloud
  4. Move (or copy) the current data directory to the new location: sudo mv /var/snap/nextcloud/common/nextcloud/data /media/my/new/data.
  5. Re-enable the snap: sudo snap enable nextcloud.

Now you don't need to bother with the external media solution: all of Nextcloud's data will be there.

Note that this only covers the raw data (e.g. files) hosted by Nextcloud. The database and apps are still in /var/snap/nextcloud/current/. I suggest you leave them there.

Note: if you have issues with the Nextcloud snap, you can log a bug against it.

theMayer
  • 103
kyrofa
  • 7,346
  • 1
  • 32
  • 26
  • This worked great! I swear, I did do a decent amount of searching and did not find your linked post. The connect ... removable-media is the piece I didn't know about; that's exactly what I was looking for and very helpful. It seems like a good entry for the snapcraft faq. Apologies for posting this in the wrong spot. Placing a bug report seemed silly when I didn't actually find a bug. – Matt Feb 12 '17 at 22:14
  • Oh no apology necessary! This should really be covered in the Nextcloud snap's README, or perhaps its wiki. – kyrofa Feb 13 '17 at 06:07
  • 4
    Another thing to mention here is that there could be a permission issue on files as nextcloud server still runs as root, while we might want to use other permissions to files (I'm using nextcloud as a syncthing front-end). To fix this, initially I was using the trick of adding an sftp storage pointing to the server itself and accessing as the wanted user so using 127.0.0.1 as host and the file owner as the user with a generated ssh key. But this wasn't the best choice. Using bindfs instead with something like bindfs --map=ubuntu/root:@ubuntu/@root, does instead the wanted job. – Treviño May 06 '18 at 02:06
  • After I move the directory I got "UniqueConstraintViolationException","Message":"An exception occurred while executing 'INSERT INTO oc_filecache...". I hadn't added any files to it, just a clean install of the snap, created the admin users and one login before moving the directory. Any clue? – Giox Nov 04 '18 at 00:52
  • nextcloud snap + syncthing - bindfs entry in fstab is only sustainable way I made this work. Nextcloud snap not using the permissions of the actual user is painful. – Jack Wasey Aug 23 '19 at 12:21
  • i noticed that the current folder is symlink to the current version of the nextcloud, what happens when we update nextcloud? Do we have to redo this again? – Major Aug 14 '20 at 22:02
  • Don't worry Major, when the snap is updated the new version runs against the edit you already made (the data is copied). You won't need to do this again. – kyrofa Sep 01 '20 at 19:24
  • I had permission issues, where nextcloud requires the datadiractory to have permission 0770. To change the permission: https://askubuntu.com/a/91054/514666 – Zheng Qu May 02 '21 at 14:42
4

Use 'stop' instead of 'disable' otherwise you won't be able to edit config.php.

  1. Enable external storage for snap: sudo snap connect nextcloud:removable-media

  2. Stop nexcloud snap: sudo snap stop nextcloud

  3. Update storage location: sudo vim /var/snap/nextcloud/current/nextcloud/config/config.php

change data location:

'datadirectory' => '/media/storage/data',

  1. Move the data directory to the storage device: sudo mv /var/snap/nextcloud/common/nextcloud/data /media/storage/

  2. Start nextcloud snap: sudo snap start nextcloud