SolutionsPrivate Clouds: Cloudforms PaaS: OpenShift Public Clouds Cloud Portfolio Building Clouds Cloud Partner Program ResourcesMedium & Large Enterprise Enterprise Solutions Business Intelligence Collaboration & Content Management Enterprise Applications Security Web Applications
Tips & Tricks: Samba Trash
Normally a file deleted by a user on a Samba share is deleted permanently. Did you know that Samba has the ability to move deleted items on a Samba share to a designated recycle folder similar to the way files are deleted on your local machine? We'll show you how and why you may want to do this in this month's Tips and Tricks: "Samba Trash"
Can I have a trash/recycle folder in Samba like I have on my desktop?
Yes. Samba has the ability to move deleted items on a Samba share to a designated recycle folder similar to the way files are deleted on your local machine. This is an advantage over the standard Samba configuration because normally if a file is deleted by a user on a Samba share it is deleted permanently. One obvious disadvantage is that this will increase the amount of disk space required on the Samba server because you are retaining deleted files. To overcome this you will need to regularly 'clean up' the recycle folders.
This FAQ assumes you have samba 3-x.x installed. This can be verified by the following command:
rpm -q samba
If you do not have the required version of Samba installed we have articles on how to update/install the correct version of Samba.
To implement the network recycle folder Samba uses a Virtual File System (VFS) module. The various VFS modules that Samba can use are in the local directory:
Documentation on the options for the recycle.so module and other VFS modules can be found in the local directory
//usr/share/doc/samba-x.x/docs/Samba-HOWTO-collection.pdf under chapter 19 or on the following website: http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/VFS.html
To implement a Samba recycle folder simply edit one of your shares to be similar to the example below:
#============================ Share Definitions ============================== [SambaShare] path = /home/scripts public = yes writable = yes browsable = yes vfs object = recycle recycle:repository = .deleted/%U recycle:keeptree = Yes recycle:touch = Yes recycle:versions = Yes recycle:maxsixe = 0 recycle:exclude = *.tmp recycle:exclude_dir = /tmp recycle:noversions = *.doc
This configuration only implements a recycle folder on the directory "Samba Share". The above options must be specified for each Samba share you want the recycle folder functionality on.
The most interesting option above is:
recycle:repository = .deleted/%U
This specifies where the deleted files will be stored. This is relative to the share path. From the above example "Samba Share" has the path /home/scripts. Therefore anything that is deleted is moved to the directory .deleted under this path. The %U variable is the username of the person currently browsing the share. So for every user that deletes a file there is a directory with their username containing all the files they have deleted.
Scott is browsing the "Samba Share" directory and deletes a file. The deleted file can now be found under
Brad is browsing the "Samba Share" directory and deletes a file. The deleted file can now be found under
It is important to note that the .deleted directory must be created prior to use. It must then allow users to write to that directory. This is just an example and can be setup differently to suit your particular situation.
For more tips and/or tricks check out the Red Hat Knowledgebase at: http://kbase.redhat.com