Recycle Bin (vfs recycle) for SMB Shares


dlandon

Recommended Posts

This is a plugin that will create a per share .Recycle.Bin folder on each smb share for files deleted on that share.  Built into samba is a module called "vfs recycle" that handles the deletion of files.  This plugin manages the vfs recycle settings using smb-shares.conf and starts and stops vfs recycle.  Basically samba is restarted with the smb-shares.conf file configured for vfs recycle.

 

The reason the folder name of .Recycle.Bin was chosen is so the recycle bin is a hidden folder.  This is the normal way a recycle bin works.

 

The way vfs recycle works when a file is deleted is to move the file pointers (directory information) to the .Recycle.Bin folder on the same share where the file is located.  Each share will have its own .Recycle.Bin folder where the files deleted from that share are located.  The .Recycle.Bin folder is created when a file on that share is deleted.

 

A .Recycle.Bin folder per share is created and contains all deleted files for that share.  This deleted file organization can be modified in the WebUI.  You can set parameters to organize deleted files by user or machine and then the file structure after that.  The deleted files can then be recovered as necessary by browsing to //Tower/share/.Recycle.Bin. 

 

You can also optionally set up an empty trash event (Hourly, Daily, or Weekly) that will delete files older than a configurable number of days.  Deleted files are dated when they are deleted and not by their original date.  You can click on a "Remove Aged Files" button on the WebUI and deleted files will be removed based on the aged days setting.

 

You can make the .Recycle.Bin folder visible in the shares by setting 'Hide "dot" files' to no in the smb settings.  You can then browse the .Recycle.Bin folders.  If the folder is not visible, you can browse to it by using //Tower/share/.Recycle.Bin.

 

I recommend setting up the weekly cron and set the age days to something that makes sense for you (default is 7 days).  That will keep the .Recycle.Bin folder from getting out of hand.

 

Note: Shares will not show up when browsing the Recycle Bin from the WebUI unless there is a .Recycle.Bin folder on that share.

 

Click on the 'Help' button on the upper right of the menu bar and you will get explanations of the settings.

 

The preferred way to install the plugin is using Community Applications or you can cut and paste this link into the "Install Plugin" line to install the plugin:

https://github.com/dlandon/recycle.bin/raw/master/recycle.bin.plg
 
Note: Be sure to remove any older plugin (prior to V6.3) before installing this new version.

 

Note: If you remove the plugin, the .Recycle.Bin share folders will not be emptied.  If you want to permanently remove the plugin, you need to empty the trash before removing the plugin.

 

Excluding Shares

 

Enter the share names to exclude from the recycle bin.  You can treat these names as wild cards.  Any share that has the text that is in the excluded share will be removed, unless single quoted.  If the share name is single quoted, the share must match exactly to be excluded.

Example:

Shares:

Joe Files

Sam Files

My Files

 

Setting exclude to 'Files' (without quotes) will exclude all three shares.  To exclude 'My Files' only set the exclude to 'My Files' (without quotes).

 

Note: You should exclude the appdata and system shares because there is no reason to have a recycle bin on those shares and it may create more samba activity than the recycle bin can handle if there is a lot of samba delete activity on those shares.

 

Excluding Directories

 

You can exclude directories similar to excluding Shares.  To exclude a directory from all shares (including UD mountpoints):

directory

 

To exclude a directory from a particular share:

share/directory

 

The full /mnt/user/ path is not necessary.

 

To exclude a directory from a UD share:

mountpoint/directory

 

The full /mnt/disks/ path is not necessary.

 

Credits: This plugin is based on the previous work of Influencer done back in the V5 days.

Edited by dlandon
Add exclude directories.
  • Like 3
  • Thanks 3
  • Upvote 3
Link to comment

The RecycleBin is a hidden share because it's name is .Recycle.Bin.  It can be seen in the unRAID shares when browsing from a Windows computer, but is not listed in the unRAID shares.  I believe the mover skips dot files when moving files from the cache drive to the array.  I'm not sure I like this for several reasons:

- It uses the cache drive and it looks like files aren't moving off the cache drive.  I see some files on disk1.

- I would think it would be best to control the share visibility, access, etc if it was a visible share and share parameters could be modified from the webgui.  For example, it might be best to make it a hidden share from the webgui.

- I'm not sure how the files are allocated.  I think it's the default high water, which would tend to always go to the first disk until it reaches the high water mark.

 

I'm really thinking that it should just be named RecycleBin without the dots.  Does anyone recall why the decision was made to make the name .Recycle.Bin so the share would be hidden?

 

I'd like to get some ideas here before I make any drastic changes, but I'm inclined to change the name and remove the dots.

 

EDIT: After doing some research it makes sense for the recycle bin to be a hidden folder.  More explanation in the OP.

Link to comment

Not sure you noticed the recent change to the behavior of the mover script.

 

The default setting for a user share is Use cache disk: NO. And mover will not move a share unless it is Use cache disk: YES. This is a recent change to the mover script to help with the (surprise!) issue of people specifying apps to use /mnt/cache/something and then having mover move it to the array. The way it worked prior to this change is mover skipped cache-only shares, now it only moves cache-yes shares.

 

Just started exercising this plugin a little to see what it does.

 

Looking at the new config/smb-extra.conf entries the plugin made, it doesn't mention cache, just /mnt/user, so the cache drive should not be involved since the share isn't configured to Use cache disk: Yes or Only.

 

I deleted a file from one of my user shares. I got new paths on 2 of my disks (not cache), and the deleted file is in one of them. Not sure why it would have created the path on 2 disks.

 

I don't think it should be necessary to have the folder hidden. Even if the user configures the Recycle Bin share to Use cache disk: Yes or Only seems like it should still work as intended. Not sure what the purpose of hiding the folder was originally. If it was for hiding it from mover, it's not obvious to me why that would be a good thing.

Link to comment

In my older version of the plg - I removed the . so it was not .Recycble.bin and prefer it that way

 

Myk

 

So you use Recycle.Bin?

 

Yes

 

I also remember it moving the deleted file on diskX to Recycble.Bin on that same diskX drive....

 

Previous - unRAID never managed the Recycle.Bin folder and you could not delete it, just its contents.  You disabled it, and then Recycle.Bin would be removed.

 

Myk

Link to comment

In my older version of the plg - I removed the . so it was not .Recycble.bin and prefer it that way

 

Myk

 

So you use Recycle.Bin?

 

Yes

 

I also remember it moving the deleted file on diskX to Recycble.Bin on that same diskX drive....

 

Myk

My deleted file did get moved to the same drive it was on. Probably that is just the way shfs makes it happen if the Recycle.Bin share can be on the same disk.

 

Don't know why it also created a path on another disk, maybe something else about the way shfs works.

Link to comment

The path that got created but not used was on disk1, so maybe it was just trying to create a folder for the share, but then when it did the move, it moved it to the disk it was on, which also created the path. In any case, I expect some of these details are not under the control of the plugin, but instead is just the way SMB and shfs are handling things.

Link to comment

Yes, from what I have experienced the deleted file remains on the same drive but moved into the Recycle directory you have setup.

 

Now that makes a lot of sense and is what I have seen.  I guess the .Recycle.Bin on the cache is because that's where the file was located.

 

I have done some reading and it seems vfs recycle does create the recycle directory on the disk the file was deleted from.  The really cool thing on unRAID is that the RecycleBin share shows all the files regardless of the disk they are on.

Link to comment

The path that got created but not used was on disk1, so maybe it was just trying to create a folder for the share, but then when it did the move, it moved it to the disk it was on, which also created the path. In any case, I expect some of these details are not under the control of the plugin, but instead is just the way SMB and shfs are handling things.

 

One of my initial concerns was that the cache was going to get loaded with deleted files and nothing would be moved off because of the .Recycled.Bin directory having a leading dot.

 

Now that I understand a little better, I'm inclined to leave things alone for now.

 

I undertook this project to update the plugin without fully understanding the vfs recycle functionality in samba.  Now that I understand it a little better, I like it even more.  With the vfs recycle being baked into samba in unRAID already, I'd like to think LT would eventually consider this as core functionality.  This plugin is not much more that a webgui for the vfs recycle, much like the apcupsd plugin that was eventually included in the core.

Link to comment

I appreciate the effort you undertook to get this plugin updated for the 6.1 series.

 

I too feel that @limetech should include this functionality natively in core unRAID. It would be a really nice set of features added with bit marketing potential and low level of work required to do so.

Link to comment

I appreciate the effort you undertook to get this plugin updated for the 6.1 series.

 

I too feel that @limetech should include this functionality natively in core unRAID. It would be a really nice set of features added with bit marketing potential and low level of work required to do so.

 

You're welcome.  This one was kind of fun.  I did have a bit of an issue with php and the new webgui methods.  bonienl helped me and I got over the last hurdle.

Link to comment

Installed fine as an update.  The RecycleBin folder didn't show anything when I accessed via Explorer after deleting a files or 2.  In the plugin settings it said it had 20kb which was a few test files I was deleting so they were there, just not visable.  I had to manually change permissions for for that folder and they magically appeared.

 

My Windows 10 laptop however can't access the RecycleBin folder at all.  Looks like it trying to connect as a domain instead of the Workgroup its set to.  :(  All other shares are accessible, and I can access it perfectly fine with my Windows 7 machine.  Grrr.  My feeling is that this is a Windows 10 issue, good old MS.

 

I noticed in the extra folder that it's setting permissions to 777, is this working?

 

Great work though dlandon!  Quick work too!  Really appreciated!

Link to comment

Installed fine as an update.  The RecycleBin folder didn't show anything when I accessed via Explorer after deleting a files or 2.  In the plugin settings it said it had 20kb which was a few test files I was deleting so they were there, just not visable.  I had to manually change permissions for for that folder and they magically appeared.

 

My Windows 10 laptop however can't access the RecycleBin folder at all.  Looks like it trying to connect as a domain instead of the Workgroup its set to.  :(  All other shares are accessible, and I can access it perfectly fine with my Windows 7 machine.  Grrr.  My feeling is that this is a Windows 10 issue, good old MS.

 

I noticed in the extra folder that it's setting permissions to 777, is this working?

 

Great work though dlandon!  Quick work too!  Really appreciated!

 

I can browse the recycle folder with all my Windows 10 computers and a Windows 7 VM.  What permissions did you change and what did you change them to?

Link to comment

Installed fine as an update.

 

Update from the older plugin?  That won't work.  The old plugin did not clean up well after itself and there will be a lot of stuff left over that can interfere with the new plugin.

 

You would need to completely remove the old plugin and possibly manually remove all the old .Recycle.Bin directories from each drive and cache drive - although I think these would go away once they are empty and you do a reboot.  Be sure that the smb-extra.conf file is deleted from /boot/config.  Remove all remnants of the old plugin from your flash drive.

Link to comment

would prefer a include in the smb-extra file for recycle bin stuff - old plugin did this and the new one does as well

 

include = /etc/samba/unassigned-shares/appdisk.conf
include = /etc/samba/unassigned-shares/appdisk2.conf#vfs_recycle_start

 

note the end of the 2nd include line...

 

Myk

 

Link to comment

My Windows 10 laptop however can't access the RecycleBin folder at all. 

 

I had the same issue on Windows 7 until I actually deleted something.  Once there was something in the recycle bin share I was able to access it over the network without a problem.

 

update - now I see you said you did delete something.  Sorry, guess I responded too fast.

Link to comment
  • dlandon changed the title to Recycle Bin (vfs recycle) for SMB Shares

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.