How To Enable Recycle Bin Like Functionality in SambaHow to configure Samba to add a Recycle Bin style function where files are not deleted strait away, but instead moved to a separate folder.
Having recently deleted some files by accident over a Samba share and having no way to recover deleted files in Linix, I thought that it may be a good idea to have something similar to the Windows Recycle Bin so that deleted files are moved rather than deleted, and can be easily recovered without risking the loss of data. The recycle bin can be emptied periodically and gives an extra layer of protection for your data. When configured, all calls to unlink (delete) a file will be intercepted and instead moved to the recycle directory. This gives the same effect as the familiar Recycle Bin on Windows computers. It also allows fast data recovery as the files are not deleted.
Installing and Configuring Samba Recycle Bin
Most modern distributions come with this module pre-installed, but if yours doesn't you can install it using the following command:
sudo apt-get install samba-vfs
Next we need to edit the Samba configuration. This is usually located in /etc/samba/smb.conf
You can either enable the recycle module globally on all shares, or specific shares. If you plan on sharing the recycle folder don't forget to exclude it from the list otherwise when you empty the recycle bin, the contents will be recycled.
Open the smb.conf file in your favourite editor, mine is Pico.
sudo pico /etc/samba/smb.conf
If you want to enable the global recycle module, add the following lines to the [general]
section, for individual shares, add the following lines to the [share name] section. You need to change the recycle:repository setting to a directory on your file system. Don't change the %U at the end as this is used to substitute the file name.
# Enable the recycle bin
vfs object = recycle
recycle:repository = /mystorage/recycle/%U
recycle:touch = Yes
recycle:keeptree = Yes
recycle:versions = Yes
recycle:noversions = *.tmp,*.temp,*.o,*.obj,*.TMP,*.TEMP
recycle:exclude = *.tmp,*.temp,*.o,*.obj,*.TMP,*.TEMP
recycle:excludedir = /recycle,/tmp,/temp,/TMP,/TEMP
In this example, I have added the lines to the Media share.
[Media]
guest account = root
force user = root
writeable = yes
delete readonly = yes
public = yes
path = /mystorage/media
# Enable the recycle bin
vfs object = recycle
recycle:repository = /mystorage/recycle/%U
recycle:touch = Yes
recycle:keeptree = Yes
recycle:versions = Yes
recycle:noversions = *.tmp,*.temp,*.o,*.obj,*.TMP,*.TEMP
recycle:exclude = *.tmp,*.temp,*.o,*.obj,*.TMP,*.TEMP
recycle:excludedir = /recycle,/tmp,/temp,/TMP,/TEMP
Restart Samba with the command sudo restart smbd
and delete a test file to verify it works.
Detailed usage guide for the various options can be found on the man pages .