Sambas Recycle VFS provides Salvage-like functionality

samba-logo.jpg
If anyone's used Novell's NSS filesystem they will know how useful the Salvage tool is. All too often a file once thought of as useless is suddenly needed or even worse a useful file accidentally deleted. In a traditional Samba setup this deleted file is lost for good unless a copy exists in backup form. This is fine for some occasions but if you have just spent eight hours working on the file going back to a twelve hour old version is not that appealing.

Samba 3's Recycle VFS (Virtual File System) module solves this problem by providing Salvage like capabilities in a nice Samba container. When a file is deleted on the share it is not deleted from the filesystem but instead its file-pointer moved to the specified recycle directory for later retrieval (just like your standard Recycle Bin).

Recycle VFS is enabled at the share level which makes it quite flexible. To enable the functionality add the following to your smb.conf file (where SambaShare is a configured share) and restart Samba:

[SambaShare]
path = /home/example
public = yes
writable = yes
browsable = yes

# Add from this point down to the share config to enable Recycle VFS....
vfs object = recycle
recycle:repository = .recycle/%U
recycle:keeptree = Yes
recycle:touch = Yes
recycle:versions = Yes
recycle:maxsixe = 0
recycle:exclude = *.tmp
recycle:exclude_dir = /tmp

This will enable the recycling functionality on the SambaShare share. Pointers to deleted files will be placed in the .recycle/Username directory on the share. To help Samba out you should create the .recycle directory in the share and make sure all users who may be deleting files on the share have read/write access to the directory.

This way if someone deletes a file they can browse to \\Server\SambaShare\.recycle\UserName and find the deleted file for easy restoration. The versions option enables multiple files of the same name to be safely deleted without fear of loosing all but one of the copies.
NOTE: The recycle directory does not have to be named .recycle, you can name it anything you like just specify the correct location in the smb.conf file.

The one issue you will need to plan for now is disk usage as deleted files will no longer be deleted. In order to reclaim disk space you will probably want to setup a cron job that searches for files in the recycle directory older than a specific time and deletes them or just do a big purge whenever storage space gets a little low.

Thanks goes out to this LUG thread and Google for pointing this out to me.

Update

Enabling this salvage functionality will result in a lot of hard disk space being lost to deleted files. Samba currently does not have an automatic clean or compression tool for these files so the easiest way to tidy them up is to remove them after a certain period of time.

To do so run the command (where /home/example is the path to the salvage enabled share):

find /home/example/.deleted -mtime +14 -type f -exec rm -r {} \;

This will delete all deleted files that are more than two weeks old. You can run this command on a regular basis by adding it as a cron job, for example to run it once a month create a file named /etc/cron.d/clean-deleted which contains:

0 3 1 * * root find /Users/david/Desktop/Temp -mtime +14 -type f -exec rm -r {} \;

This will delete the old files at 3:00am on the 1st of each month.