Hi!
Here’s the method I used to achieve my goal.
Versions used:
TrueNAS-SCALE: 22.12.4.2
Nextcloud: 29.0.6_2.0.15
- Creating a dataset on TrueNAS:
I started by creating a specific dataset for each user on TrueNAS, setting up the appropriate permissions for the user and for www-data (the web server user).
2. Mounting the volume in Kubernetes on TrueNAS:
Then, I mounted this volume in the Kubernetes (K8s) application on TrueNAS for Nextcloud. This allows Nextcloud to directly access the user’s directory via the mounted volume.
3. Creating users in Nextcloud:
In Nextcloud, I created a new user. For existing users who already had files and folders in their home directory, I used the following command to copy the entire directory structure with the correct permissions:
rsync -a /path/source/ /path/destination/
- Creating a symbolic link:
Next, I created a symbolic link between the user’s Nextcloud directory and the volume mounted from TrueNAS, ensuring that files are properly synchronized between the two:
ln -s /share/truenas/user /var/www/html/data/user
- Final result:
Now, when I log in as a user in Nextcloud, everything seems normal: the user can see their usual files and folders. When I connect via SMB to the mounted TrueNAS directory (which is mounted as a volume on Docker), I can see the user’s directory, and I can add or modify files from either Nextcloud or the SMB share.
Drawbacks:
There are two downsides to this approach:
-
Nextcloud folder structure visible via SMB:
In the SMB shared folder, you also see Nextcloud’s specific directory structure (like cache files, trash, and the files directory). It’s important to navigate to the files directory to access the user’s files, otherwise, it could cause unexpected behavior.
-
Slow file updates:
When adding or deleting files via SMB, Nextcloud doesn’t immediately detect the changes. I believe it’s possible to adjust the cache settings in Nextcloud’s configuration file to fix this, but here’s what I did to work around the issue:
-
I use the following command to force Nextcloud to rescan the directories:
su -s /bin/sh -c 'php /var/www/html/occ files:scan {USER} www-data
This command works perfectly after the scan. To automate this, a cron job can be set up on the host system (TrueNAS Scale) to run this command periodically within the container.