Projekt

Allgemein

Profil

Aktionen

Configure samba-trash

Requirements

To install samba you will need the following:
  • a installed and supported operating system (e.g. CentOS 6.x)
  • root-access
  • a fast internet connection

Preliminary Note

this is based on http://www.redhat.com/advice/tips/sambatrash.html

I’ve found a couple of tutorials on Samba, but neither one had all the right information. After fighting with it a bit, this is what I did to get it working.

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.

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: //usr/lib/samba/vfs

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

Setup

vim /etc/samba/smb.conf

#====================== Share Definitions ========================
[root]
  path = /mnt/SAMBA
  writeable = yes
  browseable = yes
  read only = No
  guest ok = Yes
  public = Yes
  valid users = jke
  create mask = 0666
  directory mask = 0777

  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 = *.bak

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.

For example:
Scott is browsing the "Samba Share" directory and deletes a file. The deleted file can now be found under /home/scripts/.deleted/Scott
Brad is browsing the "Samba Share" directory and deletes a file. The deleted file can now be found under /home/scripts/.deleted/Brad

It is important to note that the .deleted directory must be created prior to use.**((as of CentOS 6.3 this is not necessary, the directory is created automagically)) 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

Test

  • create a file on the samba-share
  • delete the file
  • check if the file has been moved to .deleted-directory
  • delete the file from .deleted
  • check if the file has gone permanently

Von Jeremias Keihsler vor mehr als 7 Jahren aktualisiert · 1 Revisionen