Jump to content
Koperfild

Samba Recycle Bin with VFS_Recycle

182 posts in this topic Last Reply

Recommended Posts

Hi,

 

I was skimming through the forum looking for a recycle bin solution for unraid an I've found one which is actually already in unraid - vfs_recycle. All that needs to be done is to add some lines of code in the config file. The only problem is that there is no direct access to the smb.conf so the only thing I could do was to create smb-extra.conf file and apply a [global] configuration there, which refereed to every share. The problem in such a case is that the [global] configuration covers the recycle bin share too and it is a vicious circle (you can not delete anything from the recycle bin).

 

I also tried to apply vfs_recycle settings per-share, but it didn't work I guess share configuration cannot be split in two lines like that:

[Multimedia]

(...)

[Multimedia]

(...)

 

I need a solution for that or a workaround.

 

Strange is that Tom has not yet implemented the feature officially. It's easy, and a lot of people are looking forward to seeing that.

Share this post


Link to post
Guest smnas

That would be an excellent idea and I would be interested in implementing this on my unRAID server. I also use FreeNAS (as a secondary backup solution), which supports a Recycle Bin style feature. If I delete some files from a share on my FreeNAS server, it places it in a folder called .recycle, which is located on the root of the share. It is a hidden folder which can be viewed given that you set Windows Explorer to see hidden files and folders. The only way that I could introduce such a setup on my unRAID server was to use a backup synchronization application called AllwaySync.

 

The scenario that I have is I use my unRAID server as my primary data storage point, followed by my FreeNAS server which I only use as a secondary backup for all my important files like photos, documents, applications, etc.. Stuff I can't be without.

I have a management server that powers on my unRAID server and initializes a comparison and synchronization between my unRAID server and FreeNAS server once a week.

If I've deleted some files or folders on unRAID, AllwaySync will mark the same files and folders for deletion on FreeNAS. The files get deleted on the FreeNAS server, but the FreeNAS server places a copy of these deleted files in the .recycle folder. AllwaySync is set to copy the deleted files from the FreeNAS server onto a folder called _DeletedFiles on my unRAID server also. 

 

Now I know it is a bit of a setup to do, but in the end I have two locations in which I can recover deleted files from both my FreeNAS server and my unRAID server. Every now and then, I simply go through both the .recycle and _DeletedFiles folders on my servers and see if the deleted files are important. If not, I just empty the contents of both folders. Once I empty both these folders, their gone for good.

 

Share this post


Link to post
Strange is that Tom has not yet implemented the feature officially. It's easy, and a lot of people are looking forward to seeing that.

 

+1 -- The lack of a Recycle Bin is the reason I have my User shares read only, and my disk shares hidden. After losing 50GB of data due to accidentally hitting the "Delete" button, I didn't want to go through that again.

 

It's an option on my little LinkStation, why not on unRAID?

 

257zyi9.png

Share this post


Link to post

Well, it seems that I have found the solution :) And it takes about one minute to enable the recycle bin or whatever to call it. It doesn't work on file system level so deletions performed from console or other protocol (NFS) are still permanent, however when it comes to samba it works like a charm.

Like I wrote in the first post the only problem is caused by the way that unraid creates config files. Those files are created by an inner script so the user can't have full control of samba configuration, however we can create an smb-extra.conf file.

 

The workaround is to add a share in the top of the document before setting the recycle bin to [global]. This seems to be working even though the [recycle bin] share lines would overlap. So this is how my smb-extra.conf file looks like:

[bIN]
path = /mnt/user/BIN
read only = No

[global]
vfs objects = recycle 
        recycle:repository = /mnt/user/BIN/%m
        recycle:keeptree = Yes
        recycle:touch = Yes
        recycle:versions = Yes
        recycle:exclude = *.tmp
        recycle:exclude_dir = /tmp
        recycle:noversions = *.doc

 

These setting create a new share called BIN which is split among(?)not sure about the expression:P the disks in our server. Any file deleted from any location will be placed there and remain until you delete it again (aka empty the recycle bin). Be careful! You can't empty the recycle bin by entering into it's folder through a disk share - it will be placed in the same folder again and again (vicious circle).

 

I attach some possible configurations of the vfs object

recycle:repository = PATH

Path of the directory where deleted files should be moved.

 

If this option is not set, the default path .recycle is used.

recycle:directory_mode = MODE

Set MODE to the octal mode the recycle repository should be created with. The recycle repository will be created when first file is deleted. If recycle:subdir_mode is not set, MODE also applies to subdirectories.

 

If this option is not set, the default mode 0700 is used.

recycle:subdir_mode = MODE

Set MODE to the octal mode with which sub directories of the recycle repository should be created.

 

If this option is not set, subdirectories will be created with the mode from recycle:directory_mode.

recycle:keeptree = BOOL

Specifies whether the directory structure should be preserved or whether the files in a directory that is being deleted should be kept separately in the repository.

recycle:versions = BOOL

If this option is True, two files with the same name that are deleted will both be kept in the repository. Newer deleted versions of a file will be called "Copy #x of filename".

recycle:touch = BOOL

Specifies whether a file's access date should be updated when the file is moved to the repository.

recycle:touch_mtime = BOOL

Specifies whether a file's last modified date should be updated when the file is moved to the repository.

recycle:minsize = BYTES

Files that are smaller than the number of bytes specified by this parameter will not be put into the repository.

recycle:maxsize = BYTES

Files that are larger than the number of bytes specified by this parameter will not be put into the repository.

recycle:exclude = LIST

List of files that should not be put into the repository when deleted, but deleted in the normal way. Wildcards such as * and ? are supported.

recycle:exclude_dir = LIST

List of directories whose files should not be put into the repository when deleted, but deleted in the normal way. Wildcards such as * and ? are supported.

recycle:noversions = LIST

Specifies a list of paths (wildcards such as * and ? are supported) for which no versioning should be used. Only useful when recycle:versions is enabled.

 

And here is the document about possible smb.conf configurations (enviromental variables is what you'll look for in there ;) )

http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

 

Regards!

Share this post


Link to post

Nice...

 

Easy too.

 

Do you think if you add BIN to the exclude list, like this:

recycle:exclude_dir = /tmp|/mnt/user/BIN

you could then delete from the BIN share without the "recursive" recycle?

 

You might need to put the directory in place for each disk, like this:

recycle:exclude_dir = /tmp|/mnt/user/BIN|/mnt/disk1/BIN|/mnt/disk2/BIN|/mnt/disk3/BIN|/mnt/disk4/BIN|/mnt/disk5/BIN

Share this post


Link to post

+1 -- The lack of a Recycle Bin is the reason I have my User shares read only, and my disk shares hidden. After losing 50GB of data due to accidentally hitting the "Delete" button, I didn't want to go through that again.

 

It's an option on my little LinkStation, why not on unRAID?

 

257zyi9.png

 

I think it gets lost amoung the chatter.

Perhaps making a request in the feature request forum will keep it there for easier viewing.

I also think a homes samba share would be a good feature too.

It's a special share that when you login with an account it will use your username as part of the directory and use your account's permissions for the directory.

Share this post


Link to post
Guest smnas

Agreed mate. Limetech, another suggestion for the upcoming v5 OS of unRAID, sounds like a valuable feature, whether users would like to have it enabled it or not. Hope to see it integrated as a feature in the future, Cheers!

Share this post


Link to post

Well done, Koperfild, and thank you!  I hope to implement this in my server soon!

Share this post


Link to post

Thanks for the info - I got this setup on my server with your instructions and it's great!

 

One pleasant side effect is that if I'm editing config files, it appears to create a "version history" of sorts for each time I save the file (I suspect this may be due to how my text editor is saving the files, and not necessarily something intended - I'm using Smultron on OS X for anyone curious).

Share this post


Link to post

This is a pretty good feature, so I just need to edit smb-extra.con file with the below:

 

[bIN]

path = /mnt/user/BIN

read only = No

 

[global]

vfs objects = recycle

        recycle:repository = /mnt/user/BIN/%m

        recycle:keeptree = Yes

        recycle:touch = Yes

        recycle:versions = Yes

        recycle:exclude = *.tmp

        recycle:exclude_dir = /tmp

        recycle:noversions = *.doc

 

Is that correct? Thanks.

 

 

Well, it seems that I have found the solution :) And it takes about one minute to enable the recycle bin or whatever to call it. It doesn't work on file system level so deletions performed from console or other protocol (NFS) are still permanent, however when it comes to samba it works like a charm.

Like I wrote in the first post the only problem is caused by the way that unraid creates config files. Those files are created by an inner script so the user can't have full control of samba configuration, however we can create an smb-extra.conf file.

 

The workaround is to add a share in the top of the document before setting the recycle bin to [global]. This seems to be working even though the [recycle bin] share lines would overlap. So this is how my smb-extra.conf file looks like:

[bIN]
path = /mnt/user/BIN
read only = No

[global]
vfs objects = recycle 
        recycle:repository = /mnt/user/BIN/%m
        recycle:keeptree = Yes
        recycle:touch = Yes
        recycle:versions = Yes
        recycle:exclude = *.tmp
        recycle:exclude_dir = /tmp
        recycle:noversions = *.doc

 

These setting create a new share called BIN which is split among(?)not sure about the expression:P the disks in our server. Any file deleted from any location will be placed there and remain until you delete it again (aka empty the recycle bin). Be careful! You can't empty the recycle bin by entering into it's folder through a disk share - it will be placed in the same folder again and again (vicious circle).

 

I attach some possible configurations of the vfs object

recycle:repository = PATH

Path of the directory where deleted files should be moved.

 

If this option is not set, the default path .recycle is used.

recycle:directory_mode = MODE

Set MODE to the octal mode the recycle repository should be created with. The recycle repository will be created when first file is deleted. If recycle:subdir_mode is not set, MODE also applies to subdirectories.

 

If this option is not set, the default mode 0700 is used.

recycle:subdir_mode = MODE

Set MODE to the octal mode with which sub directories of the recycle repository should be created.

 

If this option is not set, subdirectories will be created with the mode from recycle:directory_mode.

recycle:keeptree = BOOL

Specifies whether the directory structure should be preserved or whether the files in a directory that is being deleted should be kept separately in the repository.

recycle:versions = BOOL

If this option is True, two files with the same name that are deleted will both be kept in the repository. Newer deleted versions of a file will be called "Copy #x of filename".

recycle:touch = BOOL

Specifies whether a file's access date should be updated when the file is moved to the repository.

recycle:touch_mtime = BOOL

Specifies whether a file's last modified date should be updated when the file is moved to the repository.

recycle:minsize = BYTES

Files that are smaller than the number of bytes specified by this parameter will not be put into the repository.

recycle:maxsize = BYTES

Files that are larger than the number of bytes specified by this parameter will not be put into the repository.

recycle:exclude = LIST

List of files that should not be put into the repository when deleted, but deleted in the normal way. Wildcards such as * and ? are supported.

recycle:exclude_dir = LIST

List of directories whose files should not be put into the repository when deleted, but deleted in the normal way. Wildcards such as * and ? are supported.

recycle:noversions = LIST

Specifies a list of paths (wildcards such as * and ? are supported) for which no versioning should be used. Only useful when recycle:versions is enabled.

 

And here is the document about possible smb.conf configurations (enviromental variables is what you'll look for in there ;) )

http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

 

Regards!

Share this post


Link to post

I use this feature on my (non media) file server which holds more important data, and it's saved many users' bacon. I also have some apprehension with implementing this on unraid, due to the disk access vs user shares implementation.

 

It would be great if this feature is folded into unraid... otherwise, it'd be nice if it's acknowledged or given an implementation guideline just so future firmware updates won't raise any conflicts with it that may trigger unnecessary file movements or deletion file loops.

Share this post


Link to post

this is working well in that it creates a copy in BIN for me to retrieve.... however, I cant get it to exclude my download directories.

 

Can anyone see what I have done wrong?

regards

 

Spants

 

[bIN]
path = /mnt/user/BIN
read only = No

[global]
vfs objects = recycle 
        recycle:repository = /mnt/user/BIN/%m
        recycle:keeptree = Yes
        recycle:touch = Yes
        recycle:versions = Yes
        recycle:exclude = *.tmp *.tib 
        recycle:exclude_dir = /tmp | /mnt/user/Spants/1.5tb/downloads2 | /mnt/user/Spants/1.5tb/downloads | /mnt/user/downloads
        recycle:noversions = *.doc *.xls *.ppt

Share this post


Link to post

Try it without the spaces adjacent to the pipe separators.

 

recycle:exclude_dir = /tmp|/mnt/user/Spants/1.5tb/downloads2|/mnt/user/Spants/1.5tb/downloads|/mnt/user/downloads

Share this post


Link to post

Thanks for the suggestion but it is still putting them in the BIN :(

 

(tried doing the changes and then a reboot)

 

Is my syntax correct?

 

regards

 

Spants

Share this post


Link to post

This example simply shows the directory names being separated by spaces, and quoted if they contain an embedded space

http://www.mail-archive.com/samba@lists.samba.org/msg64331.html

They show:

recycle:exclude_dir = /tmp '/Recycle Bin' /temp /TMP /TEMP

 

Yours would then be:

recycle:exclude_dir = /tmp /mnt/user/Spants/1.5tb/downloads2 /mnt/user/Spants/1.5tb/downloads /mnt/user/downloads

 

Another example here with spaces:

http://blog.sekratech.de/2009/08/28/implementing-trash-with-samba/

 

But this example http://wiki.samba.org/index.php/Frequently_Asked_Questions

shows comma separators... and others show the pipe as I originally found it described.

 

I'd try the space first...  That person at least seemed to think it was working.

Share this post


Link to post

Any way to have this just monitor only one drive for files deleted on that only drive?

 

Share this post


Link to post

I am pretty sure that the path parameter allows you to do this.

 

I think that I have solved my problem with exclude not working - I didn't have a /tmp directory and therefore as the first parameter, it caused the other parameters not to be read.

 

Will test further...

 

 

Share this post


Link to post

 

 

These setting create a new share called BIN which is split among(?)not sure about the expression:P the disks in our server. Any file deleted from any location will be placed there and remain until you delete it again (aka empty the recycle bin). Be careful! You can't empty the recycle bin by entering into it's folder through a disk share - it will be placed in the same folder again and again (vicious circle).

 

 

How do you empty the recycle bin then?

Share this post


Link to post

From the console prompt with 'rm -rf /mnt/user/BIN/*' is what I use once I'm certain nothing that should be saved is in there.

Share this post


Link to post

From the console prompt with 'rm -rf /mnt/user/BIN/*' is what I use once I'm certain nothing that should be saved is in there.

 

Glad I asked - I would have NEVER guessed that.

thanks

Share this post


Link to post

Another question...

 

I gave this a try and deleted a file on disk15.  The deleted file is in a BIN directory on disk11.  What do I need to do so that files are not moved to a different disk?

Share this post


Link to post

Another question...

 

I gave this a try and deleted a file on disk15.  The deleted file is in a BIN directory on disk11.  What do I need to do so that files are not moved to a different disk?

You can't (not directly anyways).  It is being applied at the "user-share" level by samba.  The new file is being created based on the allocation rules for new files.  Change the rules, and the file will be created accordingly.

 

Joe L.

Share this post


Link to post

Cannot figure out why the exclude_dir is not working for me. It appears to put deleted files in the BIN directory regardless of what I try. I tried various delimiters to no avail. Perhaps it's the rest of my config that is causing problems. Any takers?

 

Thanks.

[bIN]
       path = /mnt/user/BIN
       read only = No


[global]
vfs object = recycle
       recycle:repository = /mnt/user/BIN/%m
       recycle:keeptree = Yes
       recycle:touch = Yes
       recycle:versions = Yes
       recycle:exclude = *.tmp
       recycle:exclude_dir =/tmp /mnt/disk/downloads
       security = USER
       guest account = nobody
       public = yes
       guest ok = yes
       map to guest = bad user
       map hidden = No
       map system = No
       kernel oplocks = no
       oplocks  = no
       level2 oplocks = no



[downloads]
 path = /mnt/disk/downloads
 read only = No

 

Share this post


Link to post

Another question...

 

I gave this a try and deleted a file on disk15.  The deleted file is in a BIN directory on disk11.  What do I need to do so that files are not moved to a different disk?

You can't (not directly anyways).  It is being applied at the "user-share" level by samba.  The new file is being created based on the allocation rules for new files.  Change the rules, and the file will be created accordingly.

 

Joe L.

 

Would it be possible to apply it separately to each disk (or selected disk) shares in the array?

Share this post


Link to post

Another question...

 

I gave this a try and deleted a file on disk15.  The deleted file is in a BIN directory on disk11.  What do I need to do so that files are not moved to a different disk?

You can't (not directly anyways).  It is being applied at the "user-share" level by samba.  The new file is being created based on the allocation rules for new files.  Change the rules, and the file will be created accordingly.

 

Joe L.

Yes, it can...  but that is complicated by the fact that you don't control the settings for the user-shares, unRAID does.

 

You'll find some examples using google if you search on "vfs object = recycle"

This is not a really well known feature of SAMBA, so documentation is sketchy.

 

Joe L.

 

Would it be possible to apply it separately to each disk (or selected disk) shares in the array?

Share this post


Link to post

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.