Is it possible to implement a "Recycle Bin" method in SAMBA?

1

Is it possible to implement a "Recycle Bin" method in SAMBA?

In other words, when a user deletes a file in a SAMBA share, can it be sent to the "Trash" rather than permanently delete it?

If yes, what kind of packages and settings do you need to implement for this method to be implemented?

    
asked by anonymous 14.04.2015 / 14:06

1 answer

2

In order to implement a "Garbage Bin" in SAMBA, we need at least one package, a dependency for the functionality in question:

vfs_recycle - Samba VFS recycle bin

  

vfs_recycle intercepts the deletion requests for files and moves the affected files to a temporary repository instead of deleting them permanently. This has the same effect as the Recycle Bin on Windows computers.

Step-by-step

In order to deal with the issue programmatically, we can use a script in bash which will step by step handle the checks to be made and in the end add to SAMBA configuration file the required entry (s) to include the "Trash Bin" functionality in the directories:

  • Specify the correct package name for the Linux distribution in use, in the example we use samba-vfs , but for example, in Ubuntu distributions +14.04 the name is samba-vfs-modules . This package is a dependency that allows you to implement the said "bin" functionality;

  • Specify the path to the SAMBA configuration file smb.conf , usually located at /etc/samba/smb.conf ;

  • We check if the package is installed, if not, we will execute a command to install it. Note that the way we perform the verification as well as the command to install a package may vary depending on the Linux distribution;

  • We prepare the configuration lines to add to the file smb.conf , where we should specify:

    [NomeUnico]
        path = /caminho/para/pasta/com/dados
        # Ativar caixote do lixo
        vfs object = recycle                        # objeto VFS, neste caso "recycle"
        recycle:repository = /minhaPasta/recycle/%U # caminho interno (*)
        recycle:keeptree = Yes                      # preservar estrutura de diretorias ?
        recycle:versions = Yes                      # preservar versões dos ficheiros ?
    

    (*) Internal path inside the trash bin so that each user does not see their files mixed with those of other users.

  • Finally, you need to restart SAMBA. There may also be differences here as the correct command may vary depending on the Linux distribution.

  • Example

    #!/bin/bash
    
    # Nome da dependência
    PACKAGE_NAME="samba-vfs"
    
    # Caminho para ficheiro de configuração do SAMBA
    SAMBA_CFG_FILE="/etc/samba/smb.conf"
    
    # Verificar se o pacote está instalado
    PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $PACKAGE_NAME|grep "install ok installed")
    echo "A verificar se o pacote: $PACKAGE_NAME está instalado"
    
    # Caso não tenha sido, instalar
    if [ "" == "$PKG_OK" ]; then
      echo "Não está instalado, vamos instalar."
      sudo apt-get --force-yes --yes install $PACKAGE_NAME
    fi
    
    # Enviar texto para o fim desse ficheiro
    echo "A adicionar ás configurações do SAMBA a entrada para: Partilhados"
    sudo cat >> $SAMBA_CFG_FILE << EOL
    [Partilhas]
        path = /zuul/Partilhas
        # Ativar caixote do lixo
        vfs object = recycle
        recycle:repository = /zuul/recycle/%U
        recycle:keeptree = Yes
        recycle:versions = Yes
    EOL
    
    # Reiniciar SAMBA
    echo "Feito, a reiniciar SAMBA"
    sudo service smbd restart
    

    Notes:

    Look carefully at the code before running it, otherwise the system will be damaged.

    This guide does not release the official documentation for vfs_recycle .

    For the script to be able to run, it should have execute permissions.

        
    14.04.2015 / 18:38