Enabling Recycle Bin in Samba Shares for Seamless Recovery

Are you tired of losing valuable files due to accidental deletions on your Samba shares? Enabling the file recycle bin feature is a simple yet effective solution to recover deleted files and maintain data integrity. In this post, we’ll guide you through the process of configuring the file recycle bin in Samba shares.

Configuring File Recycle Bin in Samba Shares:

To enable the file recycle bin in your Samba shares, follow these steps:


Step 1: Open the Samba Configuration File

To configure the file recycle bin in Samba, you’ll need to edit the Samba configuration file. This can be done by opening the smb.conf file using a text editor.

sudo nano /etc/samba/smb.conf

Step 2: Add the VFS Objects Directive

Add the following line to the [global] section of the Samba configuration file:

vfs objects = recycle

This directive activates the file recycle bin feature.


Step 3: Configure the Recycle Bin Repository

To specify the location of the recycle bin repository, add the following lines to the [global] section:

recycle:repository = .recycle
recycle:keeptree = yes

The recycle:repository directive specifies the directory where the recycle bin will store deleted files. The .recycle directory should be created in the root of your Samba share.


Step 4: Exclude Specific File Types

To exclude specific file types from being stored in the recycle bin, add the following line to the [global] section:

recycle:exclude = *.tmp,*.temp,*.o,*.obj,*.TMP,*.TEMP

This directive excludes files with the specified extensions from being stored in the recycle bin.


Step 5: Restart the Samba Service

After making these changes, don’t forget to restart the Samba service for the new configuration to take effect:

sudo service smbd restart

Testing the File Recycle Bin:
To test the file recycle bin feature, simply delete a file from your Samba share and verify that it has been stored in the .recycle directory.

Scripting Recycle Bin Maintenance:
You can automate the process of cleaning up the recycle bin by creating a script to remove deleted files after a specified period. This can be useful for maintaining disk space and ensuring that deleted files are not left lingering indefinitely.

Conclusion:
Enabling the file recycle bin feature in your Samba shares is a straightforward process that provides seamless recovery options for deleted files. By following these steps, you’ll be able to maintain data integrity and ensure that your files are safe from accidental deletions.