• Register
Home  //  Techbauchery  //  OS and Applications  //  Linux  //  Adding a Recycle Bin to a Samba Folder

How many times has a user deleted a file (or folder) on a network share that wasn't meant to be deleted? If I had to guess: trillions. This happens all the time and once a file is deleted on a network share, there's no way of getting it back unless you have a backup. Luckily Samba has a nifty little trick that moves a deleted file instead of actually deleting it. Very helpful if you are using Linux and Samba. Not so helpful if you are using Windows Server. Here's a snippet from my smb.conf :

    recycle:keeptree = yes
    recycle:directory_mode = 777
    recycle:versions = yes
    recycle:repository = .recycle
    recycle:touch_mtime = yes
    recycle:exclude = *.tmp, *.bak
    recycle:exclude_dir = .recycle

So when someone deletes a file, that deleted file is actually moved to a folder called .recycle within the root. No panic attacks or pulling out tapes anymore. The user or the admin can browse to the .recycle folder, move the file back and it's as if the deletion never happened.

Depending on how heavily utilized your network shares are a cron job might be in order to clean the .recycle folder out. I have my job running once every 30 days but you might want to decrease or increase the time limit.

Here's a quick example of a cron job that deleted files that have been modified 30 days or more:

find /path/to/files -mtime +30 -exec rm  {}\;