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

Asked

Viewed 278 times

1

It is possible to implement a "Recycle Bin" method in SAMBA?

That is, when a user deletes a file in a SAMBA share, it is possible to send it to "Recycle Bin", instead of permanently deleting it?

If yes, what kind of packages and configurations are needed to implement for this method to be implemented?

1 answer

2


To implement a "Trash 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 deletion requests to files and moves the affected files to a temporary repository instead of permanently deleting them. This gives the same effect as Recycle Bin on Windows computers.

Step-by-step

To deal with the issue programmatically, we can resort to a script in bash that will step by step handle the checks to be done and at the end add to the SAMBA configuration file the input(s) needed(s) to include in the directories the functionality "Trash bin":

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

  2. Specify the path to the samba configuration file smb.conf, normally situated in /etc/samba/smb.conf;

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

  4. We have prepared 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 can so that each user does not see their files mixed with those of other users.

  5. Finally, you need to restart SAMBA. Here there may also be divergences because the correct command can 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:

Carefully scan the code before executing it, otherwise the system will be damaged.

This guide does not dispense with reading the official documentation for the vfs_recycle.

To the script can be executed, it must have execution permissions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.