Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fuss:samba [2018/02/11 09:48] – [Enable Synchronization between Shadow and Samba Passwords] officefuss:samba [2024/02/22 05:35] (current) office
Line 1: Line 1:
-====== Faster Speed without Risks ====== 
- 
-Add to ''/etc/samba/smb.conf'', ''[global]'' section. 
- 
-<code> 
-[global] 
-    socket options=SO_RCVBUF=131072 SO_SNDBUF=131072 TCP_NODELAY IPTOS_LOWDELAY 
-    use sendfile = true 
-    max xmit = 65535 
-    max connections = 65535 
-    max open files = 65535 
-    min receivefile size = 16384 
-    aio read size = 16384 
-    aio write size = 16384 
-    read raw = yes 
-    write raw = yes 
-    getwd cache = yes 
-    dead time = 15 
-    kernel oplocks = yes 
-</code> 
- 
 ====== Force User and Group ====== ====== Force User and Group ======
  
Line 151: Line 130:
 pam password change = yes pam password change = yes
 </code> </code>
 +
 +====== Enable Volume Shadow Copies with ZFS ======
 +
 +If the underlying filesystem supports shadow copies then Samba can be made to utilize shadow copies. On Debian, first install ''zfs-auto-snapshot'':
 +<code bash>
 +aptitude install zfs-auto-snapshot
 +</code>
 +
 +and then enable the ''shadow_copy2'' vfs object:
 +<code>
 +[global]
 +...
 +    vfs_objects = shadow_copy2
 +    shadow: snapdir = .zfs/snapshot
 +    shadow: sort = desc
 +    shadow: format = zfs-auto-snap_%S-%Y-%m-%d-%H%M
 +    shadow:localtime = no
 +</code>
 +
 +====== Performance with ZFS ======
 +
 +At the time of writing, ZFS does not have sendfile support, so make sure to disable it for a performance boost and particularly if timeouts are to be observed:
 +<code>
 +use sendfile = no
 +</code>
 +
 +====== Enable Web Service Discovery (WSDD) Instead of NetBIOS ======
 +
 +Web Service Discovery (WSDD) is the next generation host discovery after NetBIOS has been deprecated in Windows 10 version 1511. WSDD needs a script to be ran independently of Samba. Projects such as [[https://github.com/christgau/wsdd|the wsdd python script]] can be downloaded and ran in the background in order to enable WSDD.
 +
 +====== Samba Variables not Working ======
 +
 +  * ''%M'' - defined as the variable for the client hostname will not work unless the global configuration option ''hostname lookups = yes'' is set.
 +  * ''%m'' - defined to expand to the client NETBIOS name and will not work unless ''smb ports = 139'' is defined
 +
 +====== Enable Filesystem Cache ======
 +
 +Recent versions of Samba have the ability to cache files locally via the ''fsc'' mount option. This requires that the ''cachefilesd'' daemon is installed and running. In order to enable the filesystem cache to be used with Samba, install ''cachefilesd'':
 +
 +<code bash>
 +aptitude install cachefilesd
 +</code>
 +
 +and then enable the daemon by editing ''/etc/defaults/cachefilesd'' in order to set:
 +<code>
 +RUN=yes
 +</code>
 +
 +Finally, when mounting the Samba share from a client, pass the ''fsc'' parameter along with others parameters. For instance, from ''/etc/fstab'':
 +<code>
 +//share.lan/share  /mnt/share     cifs    vers=3.1.1,fsc,username=...,password=...    0
 +</code>
 +
 +The cache can then be monitored by reading the directory ''/var/cache/fscache/cache''.
 +
 +====== Periodically Cleaning up the Recycle Bin ======
 +
 +By enabling the ''recycle'' VFS object, Samba creates a Windows and Linux-compatible recycle bin such that files deleted on the share, regardless whether they are deleted from Windows or Linux, will end up copied first into a ''.recycle'' subfolder at the top level of the share.
 +
 +The problem is that the ''recycle'' VFS object configuration does not include an option to clean up the ''.recycle'' subfolder such that all the space on the drive can end up used very quickly. One solution is to use a cron script to periodically delete files and directory that are older than a certain amount of days.
 +
 +For example, the following script:
 +<code bash>
 +#!/usr/bin/env bash
 +###########################################################################
 +##  Copyright (C) Wizardry and Steamworks 2024 - License: MIT            ##
 +###########################################################################
 +
 +###########################################################################
 +##                            CONFIGURATION                              ##
 +###########################################################################
 +
 +# Should be set to the number of days that files will be kept. Any file
 +# found to be older than this amount of days will be deleted.
 +DELETE_OLDER_THAN_DAYS=5
 +
 +# Samba mount paths with "vfs_recycle" enabled.
 +MOUNT_PATHS=( /mnt/archie /mnt/docker )
 +
 +###########################################################################
 +##                              INTERNALS                                ##
 +###########################################################################
 +
 +# Acquire a lock.
 +LOCK_FILE='/var/lock/cleanup-samba-trash'
 +if mkdir $LOCK_FILE 2>&1 >/dev/null; then
 +    trap '{ rm -rf $LOCK_FILE; }' KILL QUIT TERM EXIT INT HUP
 +else
 +    exit 0
 +fi
 +
 +for MOUNT_PATH in "${MOUNT_PATHS[@]}"; do
 +    if [ ! -d "${MOUNT_PATH}"/.recycle ]; then
 +        echo "Mount path \"${MOUNT_PATH}\" has no recyle bin."
 +        continue
 +    fi
 +
 +    find "${MOUNT_PATH}/.recycle/" \
 +        -depth \
 +        -type d -o -type f \
 +        -ctime +${DELETE_OLDER_THAN_DAYS} \
 +        -exec rm -rf '{}' \; 2>&1 2>/dev/null >/dev/null | true
 +done
 +
 +</code>
 +
 +can be dropped inside ''/etc/cron.daily'' and ran every day in order to maintain only a backlog of 5 day old files inside the ''.recycle'' folder. The script can be configured within the configuration section to set multiple Samba mount paths to be cleaned as well as the number of days after which files should be deleted.
 +
  

fuss/samba.1518342497.txt.gz · Last modified: 2018/02/11 09:48 by office

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.