Before configuring Samba Recycle Bin, make sure to install Samba on Arch Linux and configure Samba shares first. Samba Recycle Bin is similar to windows Recycle Bin and is essential Samba addition for easy recovery of deleted files. It is somewhat different than Desktop based Recycle Bins in that it creates directories as specified and moves the deleted files there.
Edit samba configuration file.
sudo nano /etc/samba/smb.conf
Scroll down quickly by holding
Configure Samba Recycle Bin
Samba Bin can be configured either globally or per-share basis with vfs_recycle module. Configuration setting specific to vfs_recycle module can be added to the global section to apply to all shares or to specific shares to apply to those shares only. Samba settings can also be applied globally and then certain options overridden per share basis.
Copy the settings to the [global] section of the configuration file.
[global] vfs object = recycle recycle:repository = /mnt/virtual/homes/%u/recycle recycle:touch = no recycle:keeptree = yes recycle:versions = yes recycle:exclude = *.tmp, *.bak, thumb.db recycle:exclude_dir = /recycle, /tmp
Samba Recycle Bin is enabled by setting
vfs object option to
recycle. By default deleted files are moved to a hidden .recycle directory within the share. This behaviour can be changed by specifying a path with
recycle:repository option. The path can point to any location even outside of the volume or share. To insert the current username in the path
%u can be used among other possible predefined values. The date modified metadata can be altered when deleting files depending on
recycle:touch option value. The full path of the deleted files can be kept or discarded with
recycle:keeptree option. Files with the same name as previously deleted files can be either deleted permanently or renamed and kept depending on the value of
recycle:versions option. Certain files are generated automatically and should generally be deleted permanently. These and other specified files can be excluded with
recycle:exclude option. Directories can be excluded as well with the
The Recycle Bin directory will be created automatically assuming appropriate permissions are set on the parent directory. If the bin directory cannot be created files will be deleted permanently so it is important to confirm by creating and deleting a test file.
One thing to keep in mind is that deleted files will be moved to the specified directory. This means that the file may be physically moved if the Recycle Bin is on a different physical device. This can be problematic when deleting large files as the move can take a long time. Permissions are set to 700 by default and will only permit the owner full access but no other users will have any access rights.
Optionally configure Samba home share so that the Recycle bin directory is accessible from the user home shares.
Restart Samba for the new configuration to take effect.
sudo systemctl restart smbd