doobyns Posted July 25, 2022 Share Posted July 25, 2022 (edited) This script allow to bypass UNRAID caching for a specified SMB Share. The Share must be already activated in the UNRAID GUI (Export set to 'Yes'). The name of the share must be filled in the SHARE_NAME parameter before running the script. SMB_PREVENT_CLIENTS_SPINUP add optional settings to the share in order to prevent creation of Thumbs.db and .DS_Store files by clients Notes: Changes made by this script aren't persistent and won't survive after a reboot, if you decide to stop using this script without reboot you can revert the cache bypass by filling SHARE_NAME with a value not corresponding to any share in use, and run the script manually, this will revert all the changes made by this script. The script will check validity and no modifications will be permanent after a reboot (you must set schedule as specified to allow script running after each reboot). If you change the SMB Security Settings oy the share (eg: you set export to "No") then you must to run the script again to reflect the settings in the script (press "Run Script" button in CA User Scripts). Installation: Install the "User Scripts" plugin from "Apps" Add a new script and paste the following script Set the schedule to "At First Array Start" Enjoy 😃 : #!/bin/bash # #This script allow to access a SMB share directly without using the cache # # By Quinto - 27 july 2022 # v.0.9.5 # settings { SHARE_NAME="share_name_without_slashes" #Options SMB_PREVENT_CLIENTS_SPINUP=true #Prevent creation of Thumbs.db and .DS_Store files by clients,set to true or false VERBOSE=0 #0=Error; 1=Info; 2=Debug } ##### No modification below this line ##### SMB_MOUNT=$(cat /etc/samba/smb-shares.conf | awk '/\['${SHARE_NAME}'\]/{flag=1;next}/\[*\]/{flag=0}flag' | sed 's/\/mnt\/user/\/mnt\/user0/g') if [[ ! $SMB_MOUNT ]] then echo -e "Auto-configured share ${SHARE_NAME} not found !\nCheck this script configuration then run it again..." if test -f /etc/samba/smb-override.conf then echo -e "Warning : Script probably running with bad configuration !\nShare ${SHARE_NAME} was probably renamed or deleted, check this script configuration then run it again..." [[ $VERBOSE -ge 1 ]] && echo "Restoring normal state: Deleting unvalid configuration" rm /etc/samba/smb-override.conf sed -i '/include = \/etc\/samba\/smb-override.conf/d' /etc/samba/smb.conf sed -i '/#smb-override script launched, deleted after a reboot/d' /etc/samba/smb.conf [[ $VERBOSE -ge 1 ]] && echo "Updating SMB configuration" smbcontrol all reload-config fi else [[ $VERBOSE -ge 1 ]] && echo "Analysing /etc/samba/smb.conf..." TOTAL_CONFIG="$SMB_MOUNT" if grep -q "include = /etc/samba/smb-override.conf" /etc/samba/smb.conf; then echo -e "Auto-configured share ${SHARE_NAME} exist...\nValues are updated"; fi; [[ $VERBOSE -ge 1 ]] && echo "Installation of smb-override in /etc/samba/smb.conf..." echo -e "\n #smb-override script launched, deleted after a reboot\n include = /etc/samba/smb-override.conf" >> /etc/samba/smb.conf if [[ $SMB_PREVENT_CLIENTS_SPINUP ]] then [[ $VERBOSE -ge 1 ]] && echo "Option to prevent unwanted spinning by Windows & Mac OS clients enabled" SMB_OPTIONS=" veto files = /.smbdelete*/.DS_Store/Thumbs.db/\n delete veto files = yes\n" else SMB_OPTIONS="" fi [[ $VERBOSE -ge 1 ]] && echo -e "UNRAID caching feature is now bypassed when using SMB share : ${SHARE_NAME}" [[ $VERBOSE -ge 2 ]] && echo -e "nNew configuration is:\n${SMB_MOUNT}\n${SMB_OPTIONS}" echo -e "#smb-override script launched, deleted after a reboot\n\n[${SHARE_NAME}]\n${SMB_MOUNT}\n${SMB_OPTIONS}" > /etc/samba/smb-override.conf [[ $VERBOSE -ge 1 ]] && echo "Updating SMB configuration" smbcontrol all reload-config echo "Done, script was correctly executed !" fi echo "" exit 0 Edited July 26, 2022 by doobyns updated the script Quote Link to comment
kizer Posted July 26, 2022 Share Posted July 26, 2022 What exactly does this do? Does it simply put files into the Array vs the Cache? If so isn't there already a simple setting in shares to avoid that. Just curious. Does this basically simply /mnt/cache0/ShareName ? Quote Link to comment
doobyns Posted July 26, 2022 Author Share Posted July 26, 2022 1 hour ago, kizer said: What exactly does this do? Does it simply put files into the Array vs the Cache? If so isn't there already a simple setting in shares to avoid that. Just curious. Does this basically simply /mnt/cache0/ShareName ? yes it's exactly that, where is the setting in shares to avoid using the cache for smb ? Quote Link to comment
JonathanM Posted July 26, 2022 Share Posted July 26, 2022 40 minutes ago, doobyns said: where is the setting in shares to avoid using the cache for smb ? Quote Link to comment
doobyns Posted July 26, 2022 Author Share Posted July 26, 2022 (edited) 1 hour ago, JonathanM said: i need to have cache pool on this share for others operations, but when i copy a large amount of files with SMB i need to avoid filling the cache, and i don't use the cache normally, i use it only for the plex smart caching script here : https://forums.unraid.net/topic/92126-smart-caching-script/ I use my cache as "read only", some data only copied on the cache but all my files stay safe on the array, it would be simpler to have a button in the SMB SECURITY SETTINGS of the share to select if i want use the cache or bypass it, but it's not implemented yet... Edited July 26, 2022 by doobyns Quote Link to comment
kizer Posted July 26, 2022 Share Posted July 26, 2022 Most people Map \\192.168.X.X\ShareName - which obviously copies to your share in windows. however you can map \\192.168.X.X\user0\ShareName - Which Bypasses the Cache drive and writes directly to the array. So in a sense you can pick and choose which files goto the Cache and which does not directly just by pointing them to either mapping of user or user0 Quote Link to comment
Kilrah Posted July 26, 2022 Share Posted July 26, 2022 15 minutes ago, kizer said: \\192.168.X.X\user0\ShareName - Which Bypasses the Cache drive and writes directly to the array. This sounds interesting, never come across it being documented.... Is there something special to do for this to work? I just get "not found" from Windows. Quote Link to comment
doobyns Posted July 26, 2022 Author Share Posted July 26, 2022 25 minutes ago, kizer said: Most people Map \\192.168.X.X\ShareName - which obviously copies to your share in windows. however you can map \\192.168.X.X\user0\ShareName - Which Bypasses the Cache drive and writes directly to the array. How do you do to change the mapping in the unraid GUI? Quote Link to comment
trurl Posted July 26, 2022 Share Posted July 26, 2022 34 minutes ago, kizer said: \\192.168.X.X\user0\ShareName Not sure what you had in mind there. user0 isn't accessible over the network. You can access shares, or you can access disks if you enable disk sharing (not recommended). You can even create a rootshare with Unassigned Devices so all shares appear under rootshare on the network. rootshare effectively give you access to /mnt/user, but no way to get /mnt/user0. Quote Link to comment
trurl Posted July 26, 2022 Share Posted July 26, 2022 3 hours ago, doobyns said: I use my cache as "read only", some data only copied on the cache but all my files stay safe on the array Still don't understand what this is trying to accomplish though. Files on cache and files on the array are both part of user shares. The idea that all files are on the array and also some files are on cache. Doesn't make any sense. If you make a share cache:no, no new files will be written to cache, but all files on cache and array are included in the user share. Quote Link to comment
kizer Posted July 26, 2022 Share Posted July 26, 2022 13 minutes ago, trurl said: Not sure what you had in mind there. user0 isn't accessible over the network. You can access shares, or you can access disks if you enable disk sharing (not recommended). You can even create a rootshare with Unassigned Devices so all shares appear under rootshare on the network. rootshare effectively give you access to /mnt/user, but no way to get /mnt/user0. Thanks for the Clarification. Now I feel a little dumb now that I just checked myself when I should of known better. I've moved files before to user0 internally from command line when I wanted to move files around knowing I didn't want them to go to the cache first. Quote Link to comment
doobyns Posted July 26, 2022 Author Share Posted July 26, 2022 (edited) 43 minutes ago, trurl said: If you make a share cache:no, no new files will be written to cache, but all files on cache and array are included in the user share. Thanks for the information, i read this in the doc : Quote However if you manually create a top level folder on any drive the system will automatically consider this to be a user Share and give it default settings. I understand that i just have to make a top level folder on any pool and it will be considered by the filesystem as the same as it would be selected as "cache" in the gui. My question is when the same data is stored on two same top level folders, one on a array (on a hard drive) and another on a pool (eg on a ssd), when accessing to the array via /mnt/user/toplevelfolder/mydata, how to tell fuse file system to read the file on the ssd (pool) rather than the hard drive (array) ? It will pick automatically the fastest device ? Edited July 26, 2022 by doobyns Quote Link to comment
JonathanM Posted July 26, 2022 Share Posted July 26, 2022 46 minutes ago, doobyns said: My question is when the same data is stored on two same top level folders, one on a array (on a hard drive) and another on a pool (eg on a ssd), That is not a condition that is considered normal, it can result in things happening that seem strange. I.E. you delete a file, refresh, and the file is still there, because the second instance is now revealed. It's normally not something you do on purpose, typically it's considered an error. If you are interacting with the user share system normally it can never happen. The fuse system does work down the disks one at a time, the first instance of that file name will be the one presented in /mnt/user. I can't remember exactly what the order is though. Order is not configurable, beyond renaming devices. Bottom line, you are colouring outside the lines on this one, things may not work as desired. Quote Link to comment
Kilrah Posted July 27, 2022 Share Posted July 27, 2022 (edited) What I've been doing to bypass the built-in shares is simply fire up a Docker container with another samba instance (docker-compose plugin, dperson/samba container, br0 network, give it another static ip on my network, and share one/more folders I want). In my case it was to share a folder as SMBv1 and with settings that make it compatible with W95/98/XP to transfer stuff to my retro machines without affecting the main shares but that would also work just fine to share something under user0. version: '3.4' services: samba: image: dperson/samba environment: TZ: 'Europe/whatever' USERID: 1000 GROUPID: 100 networks: lan_macvlan: ipv4_address: 192.168.0.8 ports: - "137:137/udp" - "138:138/udp" - "139:139/tcp" - "445:445/tcp" read_only: true tmpfs: - /tmp restart: unless-stopped stdin_open: true tty: true volumes: - /mnt/user/share/XP:/mnt:z #- /mnt2:/mnt2:z command: '-s "SMBv1;/mnt;yes;no;yes;all" -r -g "lanman auth = yes" -g "client lanman auth = yes" -g "client plaintext auth = yes" -g "ntlm auth = yes" -g "server min protocol = nt1"' networks: lan_macvlan: name: lan_macvlan Edited July 27, 2022 by Kilrah Quote Link to comment
trurl Posted July 27, 2022 Share Posted July 27, 2022 15 hours ago, doobyns said: I understand that i just have to make a top level folder on any pool and it will be considered by the filesystem as the same as it would be selected as "cache" in the gui. If a share is created automatically in this way, it will have default settings. One of those defaults is cache:no I just tested this by creating a top level folder directly on cache. The resulting user share is cache:no despite the fact that it only has files on cache. So any new files would go to the array. 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.