Jump to content
Koperfild

Samba Recycle Bin with VFS_Recycle

182 posts in this topic Last Reply

Recommended Posts

Wow I really like this. I like how it creates a Folder with in a folder keeping the exact path. So you know exactly where a file is supposed to go back if when you need to put it back.

 

Some say you need to reboot to make this work or create a BIN share. Nope I just simply added the above mentioned code into a smb-extra.conf and added and deleted a file to see if it would work. Sure enough.

Share this post


Link to post

I dont know what changed, but I had to reboot my server again and it started working.  I did notice that when a file does end up in the BIN folder it doesnt show the top level directory, is there anyway to get that to show?

Delete from /mnt/user/Downloads/Apps

shows as /mnt/user/BIN/username/Apps

would like to have it show that it came from the Downloads directory

Share this post


Link to post

I noticed what I thought was funny.

 

/mnt/user/BIN/acer/Downloads/

 

acer being the name of my computer and Downloads being the folder to which I deleted a file from. Of course I deleted these files using my PC since I do actually have one folder with read/write access

Share this post


Link to post

and if you delete the files from other machines, they will have their own "base" directory.

 

 

root@Tower:/mnt/user/RecycleBIN -> ls -l
total 0
drwx------ 1 root root 144 2011-07-27 21:16 192.168.1.101/
drwx------ 1 root root  72 2011-07-27 08:18 192.168.1.103/
drwx------ 1 root root  72 2011-07-08 18:16 192.168.1.104/
drwx------ 1 root root 120 2011-07-09 15:36 192.168.1.111/
drwx------ 1 root root  88 2011-07-13 21:33 192.168.1.140/
drwx------ 1 root root 208 2011-07-29 10:53 graywolf-laptop/
drwx------ 1 root root  72 2011-07-27 23:34 htpc/

Share this post


Link to post

That's not funny at all, as it's exactly how you configured it with the following line:

 

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

 

the %m means the NetBIOS name of the client machine. You can see the other variables you can use by looking at the 'VARIABLE SUBSTITUTIONS' section here: http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

 

These substitutions are mostly noted in the descriptions below, but there are some general substitutions which apply whenever they might be relevant. These are:

 

%U

 

    session username (the username that the client wanted, not necessarily the same as the one they got).

%G

 

    primary group name of %U.

%h

 

    the Internet hostname that Samba is running on.

%m

 

    the NetBIOS name of the client machine (very useful).

 

    This parameter is not available when Samba listens on port 445, as clients no longer send this information. If you use this macro in an include statement on a domain that has a Samba domain controller be sure to set in the [global] section smb ports = 139. This will cause Samba to not listen on port 445 and will permit include functionality to function as it did with Samba 2.x.

%L

 

    the NetBIOS name of the server. This allows you to change your config based on what the client calls you. Your server can have a “dual personality”.

%M

 

    the Internet name of the client machine.

%R

 

    the selected protocol level after protocol negotiation. It can be one of CORE, COREPLUS, LANMAN1, LANMAN2 or NT1.

%d

 

    the process id of the current server process.

%a

 

    The architecture of the remote machine. It currently recognizes Samba (Samba), the Linux CIFS file system (CIFSFS), OS/2, (OS2), Windows for Workgroups (WfWg), Windows 9x/ME (Win95), Windows NT (WinNT), Windows 2000 (Win2K), Windows XP (WinXP), Windows XP 64-bit(WinXP64), Windows 2003 including 2003R2 (Win2K3), and Windows Vista (Vista). Anything else will be known as UNKNOWN.

%I

 

    the IP address of the client machine.

%i

 

    the local IP address to which a client connected.

%T

 

    the current date and time.

%D

 

    name of the domain or workgroup of the current user.

%w

 

    the winbind separator.

%$(envvar)

 

    the value of the environment variable envar.

 

The following substitutes apply only to some configuration options (only those that are used when a connection has been established):

 

%S

 

    the name of the current service, if any.

%P

 

    the root directory of the current service, if any.

%u

 

    username of the current service, if any.

%g

 

    primary group name of %u.

%H

 

    the home directory of the user given by %u.

%N

 

    the name of your NIS home directory server. This is obtained from your NIS auto.map entry. If you have not compiled Samba with the --with-automount option, this value will be the same as %L.

%p

 

    the path of the service's home directory, obtained from your NIS auto.map entry. The NIS auto.map entry is split up as %N:%p.

 

There are some quite creative things that can be done with these substitutions and other smb.conf options.

 

 

Share this post


Link to post

Edit: Rewritten 13.feb 2012

 

I've learned two things:

[*]The exclude dir must be relative to the samba share. For instance setting 'recycle:exclude_dir = Tmp' prevents dirs named /mnt/user/myshare/Tmp from being recycled in the share /mnt/user/myshare. Exclude.dir with absolute paths relative to linux filesystem does not work for me.

[*]The recycle bin doesn't quite like one global recycle bin for all shares. Sometimes (before reboot perhaps?) it won't catch deleted files from samba shares which are not standard unRaid user shares, such as flash, disk1, disk2, the recycle bin. I have never seen it recycle files deleted from disk1,disk2, but it recycles the dirs deleted from disk1,disk2. I have seen it recycle the files from the recycle bin, though adding the exclude.dir=BIN avoids the vicious circle (but you have to delete an extra time)

Two th

 

The following samba recycle bin configuration works for me with regards to avoiding the vicious circle of deletion. It places a recycle bin directory within each samba share (also flash, whether you like it or not). The path of the recycled files also contains the name of the user share (%S) from which the file was deleted (thus avoiding possible collisions in recycle bin).

 

# Documentation http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html
# Forum topic http://lime-technology.com/forum/index.php?topic=5446.0
# Parameters: http://lime-technology.com/forum/index.php?topic=5446.msg135527#msg135527
# %S Samba share name (which in unRaid equals the user share name), eg. Storage
# %P User share full path, eg /mnt/user/Storage
#
# To apply changes execute: /etc/rc.d/rc.samba restart
# If the single custom bin solution is chosen, create the dir manually, and grant it g+rwx permissions

[global]
vfs objects = recycle 
recycle:repository = %P/.Recycle.Bin
        recycle:keeptree = Yes
        recycle:touch = Yes
        recycle:versions = Yes
        recycle:exclude = *.tmp	
        recycle:exclude_dir = .Recycle.Bin
        recycle:noversions = *.doc *.xls *.ppt

 

Share this post


Link to post

I know this is old; but I have this working in Beta12, but now trying on another server with RC5 and its not working.

 

exclude_dir does nothing!

 

Good part is, the cyclical recycle bin doesn't occur (i can remove anything from the recycle bin without it looping).  but no other exclude works! :(

Share this post


Link to post

Well; after lots of testing and staying up way to late last night; i know what the issue is.

 

exclude_dir doesn't work at the share level.

 

For example: I'm trying to exclude my share /esxi_backup, by excluding the directory, 'esxi_backup' or '/esxi_backup'

But the recycle bin plugin doesn't see that as a directory, that is the main directory.  If I put a directory called 'esxi_backup' in the share, it works.

so I would have /esxi_backup/esxi_backup and that works (anything delete from in that directory doesn't get recycled).

 

Apparently you can not set the recycle bin to only work on selected shares, it must be global (all) or nothing.

 

EDIT:

Strange: further testing seems to show that its more an issue with the user shares for some reason.  If I put in the full path, both /mnt/disk1/esxi_backup and /mnt/user/esxi_backup - only when accessing the share via /disk1/esxi_backup does it work.  May still be due to when at /esxi_backup (the user share) you are at the root share level (where it seems you can not exclude it from the recycle bin).

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.

I've tried spaces, comma's, pipes... nothing seems to work for multiple exclude dirs.

 

I'm trying to exclude my /mnt/cache/Downloads folder, but if there is a way to disable the recycle.bin for the whole cache disk, that would be ok as well, but i guess i just have to add /mnt/cache to the exclude list. IF i can manage to add multiple exlude_dirs...

 

Also, if you are using cached user shares, and you delete a file on a user share, the recycle.bin folder is created on the CACHE disk... which is basically correct for 'normal' data, but NOT for a recycle.bin. The recycle.bin is then moved by MOVER every night, to 'a' place in the array...

 

Is there a way to use these recycle.bin stuff on physical DISKS only? So if i remove an item from a (cached) user share, the ACTUAL disk where this item fysically resides, will get a recycle.bin folder with that deleted file, and NO recycle.bin is created on the cache disk?

 

Or even better, a 'special' user share which IS a recycle bin? So whatever you delete, it goes to the RECYCLE.BIN user share? I think that is even better and simpler to achieve?

 

I can imagine deleting stuff, which then dissapears from the user share and is 'virtually' moved to a recycle.bin share, which, like the mover script, can be setup so it will actually delete stuff every night, or week or month, or stuff that is >10 days old etc. Once the 'DELETER' is running, it is actually deleting.

Share this post


Link to post

This is how I have mine setup:  The recycle.bin is always in the root folder of the share and the user on who deletes the file/folder is shown.  This works great for me.  some of the topics for reference is #commented

 

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

# Forum topic http://lime-technology.com/forum/index.php?topic=5446.0

# %S Samba share name (which in unRaid equals the user share name), eg. Storage

# %P User share full path, eg /mnt/user/Storage

# %u Username of the current service, if any

# To apply changes execute: /etc/rc.d/rc.samba restart

# If the single custom bin solution is chosen, create the dir manually, and grant it g+rwx permissions

 

[global]

vfs objects = recycle

recycle:repository = %P/.Recycle.Bin/%u

        recycle:keeptree = Yes

        recycle:touch = Yes

recycle:touch_mtime = Yes

        recycle:versions = Yes

        recycle:exclude = *.tmp

        recycle:exclude_dir = .Recycle.Bin

 

 

Share this post


Link to post

This is how I have mine setup:  The recycle.bin is always in the root folder of the share and the user on who deletes the file/folder is shown.  This works great for me.  some of the topics for reference is #commented

 

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

# Forum topic http://lime-technology.com/forum/index.php?topic=5446.0

# %S Samba share name (which in unRaid equals the user share name), eg. Storage

# %P User share full path, eg /mnt/user/Storage

# %u Username of the current service, if any

# To apply changes execute: /etc/rc.d/rc.samba restart

# If the single custom bin solution is chosen, create the dir manually, and grant it g+rwx permissions

 

[global]

vfs objects = recycle

recycle:repository = %P/.Recycle.Bin/%u

        recycle:keeptree = Yes

        recycle:touch = Yes

recycle:touch_mtime = Yes

        recycle:versions = Yes

        recycle:exclude = *.tmp

        recycle:exclude_dir = .Recycle.Bin

That works great for me as well... Now try to exclude some other drive (for example, the entire share) and see if it works.  i.e.

recycle:exlude_dir = .Recycle.Bin ShareName

 

where ShareName is /mnt/user/ShareName

 

That wont work.  Only files in /mnt/user/<ANY SHARE>/ShareName will be excluded from the recycle bin.

Share this post


Link to post

This is how I have mine setup:  The recycle.bin is always in the root folder of the share and the user on who deletes the file/folder is shown.  This works great for me.  some of the topics for reference is #commented

 

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

# Forum topic http://lime-technology.com/forum/index.php?topic=5446.0

# %S Samba share name (which in unRaid equals the user share name), eg. Storage

# %P User share full path, eg /mnt/user/Storage

# %u Username of the current service, if any

# To apply changes execute: /etc/rc.d/rc.samba restart

# If the single custom bin solution is chosen, create the dir manually, and grant it g+rwx permissions

 

[global]

vfs objects = recycle

recycle:repository = %P/.Recycle.Bin/%u

        recycle:keeptree = Yes

        recycle:touch = Yes

recycle:touch_mtime = Yes

        recycle:versions = Yes

        recycle:exclude = *.tmp

        recycle:exclude_dir = .Recycle.Bin

I'm using the same one. Now you try to delete something from a CACHED user share. The deleted item will NOT be placed in the recycle bin for that share, but a recycle.bin is created ON THE CACHE DRIVE... so that the mover can MOVE this recycle.bin back to the user share at night...

 

Surely this is not what you want...

 

Furthermore, like i said, adding multiple exclude dirs doesnt work...

Share this post


Link to post

...

        recycle:exclude_dir = .Recycle.Bin

...

Now you try to delete something from a CACHED user share. The deleted item will NOT be placed in the recycle bin for that share, but a recycle.bin is created ON THE CACHE DRIVE... so that the mover can MOVE this recycle.bin back to the user share at night...

 

The share name ( .Recycle.Bin ) begins with a period. The mover ignores directories beginning with a period.

Share this post


Link to post

The share name ( .Recycle.Bin ) begins with a period. The mover ignores directories beginning with a period.

True, but that still means that ALL recycle bins will be placed at the cache drive when you delete from a cached user share... so if you delete stuff from different cached user shares, you get a unmanagable collection of recycle bins cluttering your cache drive. Not so good.

 

I want a recycle bin on root level of each PHYSICAL disk, and the cache drive should be excluded. So if i delete something from user share 'series/seasaon/episode/' the file is placed in the recycle bin of the disk were the actual file was stored.

Share this post


Link to post

I've implemented this and it's working great. 

 

I've been able to empty my BIN through the same SMB connection that I use to delete files.  I'm not sure why my experience is different then others in this thread.  Perhaps it's something in v5rc5?

 

 

Share this post


Link to post

Another question before i invent the wheel again... is there a script or anything that can find and iterate through all the .Recycle.Bin's  that are created, and can delete or 'empty' them all at once?

Share this post


Link to post

rm -rf /mnt/user/.Recycle.Bin/*

Doesnt that just only delete THAT one?

I have recycle.bins in a lot of different locations, e.g.:

 

/mnt/user/Downloads/.Recycle.Bin

/mnt/user/TV Series/.Recycle.Bin

/mnt/cache/.Recycle.Bin

/mnt/disk3/TV Series/.Recycle.Bin

/mnt/disk2/TV Series/.Recycle.Bin

/mnt/disk1/Downloads/.Recycle.Bin

 

the script i'm using is:

[global]
vfs objects = recycle 
    recycle:repository = %P/.Recycle.Bin
        recycle:keeptree = Yes
        recycle:touch = Yes
        recycle:versions = Yes
        recycle:exclude = *.tmp
        recycle:exclude_dir = .Recycle.Bin

Share this post


Link to post

Oh, didn't notice you had your setup completely different by using "%P" in the repository statement.

 

find /mnt/user/ -type d -name .Recycle.Bin -exec rm -rf {} \;

 

This will find all directories named .Recycle.Bin in /mnt/user/ and execute the command to remove them. The {} is syntax to replace it with the name of the directory found.

 

To see what it would find without doing anything use:

 

find /mnt/user/ -type d -name .Recycle.Bin

 

If /mnt/user only picks up share names or you want to run against a specific disk:

 

find /mnt/disk* -type d -name .Recycle.Bin -exec rm -rf {} \;

find /mnt/disk3 -type d -name .Recycle.Bin -exec rm -rf {} \;

Share this post


Link to post

Oh, didn't notice you had your setup completely different by using "%P" in the repository statement.

I saw that in samples here? But i guess having one central place is better.

I'm now using /mnt/user/.Recycle.Bin/%P so its centralized, but i can still tell where the file(s) came from using %P.

 

Share this post


Link to post

Did anyone figure out the best solution/config to make this work?

 

Also is this going to be a requested "feature" after 5.0 Final comes out?

 

Myk

 

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.