Enable Recycle Bin in Samba 4

Hi

I have SAMBA 4 server installed on OpenWrt and I would like to enable the recycle bin feature. There are quite a few configuration files for Samba such as

  • /etc/samba/smb.conf
  • /etc/samba/smb.conf.template
  • /etc/config/samba4

so I am unsure where I should be applying the following configuration:-

	vfs objects 'recycle'
	recycle:repository '.recycle'
	recycle:keeptree 'yes'
	recycle:versions 'yes'

When I add the lines above to the /etc/config/samba file, it breaks the configuration when I try to view it via the LuCI app.

These are the SAMBA parameters I'm going by https://www.samba.org/samba/docs/current/man-html/vfs_recycle.8.html

Can anyone suggest where I'm going wrong here please?

Many thanks

Will

Sorry for the late answer, but the easiest method would be to just add recycle to the luci Vfs objects field. This will use the default settings and needs no extra setup.

The problem is that we don't have support for all the vfs modules extra parameters. So if you want to run none default values for a vfs module you can either try add them to the global's section in /etc/samba/smb.conf.template or you have to remove your share from the uci/config and directly add it to the smb.conf.template where you can than also add all the vfs special options.
You can check what to add in the template if you check the "live" /tmp/etc/smb.conf just copy&paste your share from the end of this file to the template and add the VFS stuff.

It gave me a hard time as well, but I now got it working :slight_smile:

  • Understand the consequences, before you enable the recycle bin: The LuCi config extension file used by LuCi is not compatible with the recycle bin config parameters. But samba4 on OpenWRT 23.05 does support the recycle bin (at least that is the version 23.05.3 I am using right now). You can no longer use the LuCi GUI click boxes of your samba share after the following changes, all your config will then be in the template file.
  • Make sure to have a fully working OpenWRT samba share config before you continue with this recipe.
  • Preferably backup your OpenWRT samba config files first
  • You do not need additional opkg packages for the samba recycle bin

This is what you need to do via SSH connection to the OpenWRT device, to enable the samba file share recycle bin:

  1. Create a folder for the recycle bin on the drive of your share (your path may look different):
mkdir /mnt/share/.recycle
chmod 777 /mnt/share/.recycle

  1. extract the autogenerated text parts related to your share, in my case [store] from /var/etc/smb.conf and copy it to a text editor. You will need it in the next step (note that your samba parameters may likely look a bit different):
# this is sample, your parameters will look different
[store]
	path = /mnt/store
	force user = root
	force group = root
	valid users = user
	create mask = 0666
	directory mask = 0777
	read only = no
	guest ok = yes
	vfs objects = io_uring

  1. edit /etc/samba/smb.conf.template right before the ######### Dynamic written config options ######### and add your stuff, it should then look similar to this:
#....some stuff will already be in your config file....

	#inherit owner = windows and unix
################################################################

# this is stuff you add in from step 2 of this recipe combined with the recycle bin parameters that you want to use:
[store]
	path = /mnt/store
	force user = root
	force group = root
	valid users = user
	create mask = 0666
	directory mask = 0777
	read only = no
	guest ok = yes
	vfs objects = io_uring recycle

	recycle:keeptree = yes
	recycle:versions = yes
	recycle:touch = yes
	recycle:touch_mtime = no
	recycle:minsize = 0
	recycle:maxsize = 5368709120
	recycle:repository = /mnt/store/.recycle

######### Dynamic written config options #########

!!! Pay also attention to append the text parameter "recycle" to the line vfs objects = io_uring, that you likely have extracted in step 2. As this is required to load the recycle bin extension module.


  1. Edit /etc/config/samba4, Remove all stuff except a single line:
config samba

  1. Restart samba
/etc/init.d/samba4 stop
/etc/init.d/samba4 start
1 Like