Greetings Forum:

Can somebody please point me to the recycle directory settings for Turnkey Linux File Server cifs/samba shares?  I've searched the webmin interface and cannot locate a setting to limit the maximum size of the .recycle directories.  Is there a global size setting for all shares or a way to easily empty all share .recycle directories?

 

Replies (3)

It doesn't seem like there is an OOTB solution...

Reply 1

Looking at the Samba vfs_recycle man page I can't see any support for limiting the recycle bin size. There are file size limits there, although I'm not sure if they're adjustable within Webmin. If not, the config file is /etc/samaba/smb.conf and you can use the pre-installed 'nano' to edit it (it's a commandline text editor which is somewhat like Notepad).

So bottom line, I don't think that what you want is possible OOTB.

However, this is Linux, so (pretty much) anything is possible if you really want it! :)

Digging in a bit deeper, I note that it's possible to adjust the timestamps when moving to the recycle bin. There is also a tool called tmpreaper which will clean up files based on timestamp. That still doesn't meet your requirements re filesize, but using these bits, together with a function to get file tree size, we could create a (daily?) cron job to check the size of the .recycle directory and if it's over a certain size, remove files older than X days. Then recheck the file tree size and if it's still not the desired size, reduce the age filter by a day and clean again. Rinse and repeat until the .recycle directory is smaller than the desired size. So to put all this together, here is that basis of a script (perhaps save it as /usr/local/bin/recycle-cleanup?!):

#!/bin/bash -e
KEEP_DAYS=61 # default time to keep; in days + 1
KEEP_SIZE=512 # default file tree size to keep; in MB
RECYCLEBINS="/srv/storage/docs " # space separated list of recyclebin locations
treesize() {
    # return the disk space size (in MB) used by the filetree
    du -cms "${@}" | grep total | tr '[[:space:]]' '+' | cut -d+ -f1
}

for recyclebin in ${RECYCLEBINS}; do
    while [[ "$(treesize ${recyclebin})" -gt "${KEEP_SIZE}" ]]; do
        KEEP_DAYS=$((KEEP_DAYS-1))
        tmpreaper --verbose ${KEEP_DAYS}d ${recyclebin}
    done
done

Please note that I haven't tested this at all so it may requires some more tweaking. Plus I haven't described how we might set this up as a cron job. However, I've already spent more time on this than I ideally should have. So please let me know if you want to proceed and I'm happy to work with you to get this working as desired.

Glad is was useful! :)

Reply 2

Glad that my ideas got you pointed in the right direction and ended up being useful; albeit in a somewhat indirect way. :)

Greetings again Jeremy:

Reply 3

Greetings again Jeremy:

I like your solution and do appreciate your time throwing something together.  I will play with your script more in the future - it gave me a few ideas.

I have some scripts that are triggered in crontab to automatically tar a series of vzdump (Proxmox backups) of numerous containers and virtual machines.  These can get large in size and deleting the old ones over a period of time silently chewed up a noticeable amount of my pool storage!  I found the culprits in my .recycle directory.

It looks like I can modify the config file and use recycle:exclude_dir to exclude the directory that I use specifically for bakcups to solve my problem.  Thank you for pointing me to Samba VFS recycle man page!