Link to home
Start Free TrialLog in
Avatar of mac_g
mac_gFlag for Saudi Arabia

asked on

[ Linux ] how to configure recycle bin like feature in Linux

OS : Linux

if there any file accidentally deleted we want it to preserve in some location, so that we can recover file incase required.
In other words, this is almost the same feature like in windows -recycleBin

please advise the steps to configure if this possible in windows

Thanks for your support -
Avatar of jeff_01
jeff_01

It depends how you delete the file.

If you deleted it using the rm command then you would need software recovery tools to recover the file.

Some desktop environments like Gnome, KDE etc will have a similar version of windows recycle bin called Trash. If you delete a file from in the GUI then it should be available in Trash.  There are some scripts available on the web that simulate the function of "Trash" or Recycle Bin, so when deleting a file you use the script instead of rm.  Also there's a library called libtrash that will intercept delete commands and shift the files to a trash directory. Information on it can be found below. Ive never used it myself though.

ftp://hpux.connect.org.uk/hpux/Development/Libraries/libtrash-0.2/libtrash-0.2.README.html
Here is something to look at as well. It will make the rm command move the file to a trash location instead.

http://www.webupd8.org/2010/02/make-rm-move-files-to-trash-instead-of.html
Hello mac_g,

can you please elaborate more? I suppose you want this on a Linux samba / nfs file server? You have the recycle bin on every major desktop environment in linux (like gnome, kde...).

That said, you have the major problem / solution here: Recycle Bins are a client side implementation, eg. from your Desktop Environment. You can even have this in the shell by aliasing the rm command.

If you want to have this server side, is no such thing to my knowledge. The only way to achieve this are backups.
The best way would be to use file system events ('in_delete') for that. Though there is incrond, the lack of recursive operations would limit this to a special folder only.

There is one way I consider relatively elegant for a few scenarios: File system snapshots.

You could use for instance LVM in a cron script to make a FS snapshot cycle. Mount this and make a read only share. You can rotate snapshots to your liking.

Keep in mind the thing I said above about a few scenarios. LVM snaps are relatively slow and eat up a lot of the IOPS of your storage, esp. if you maintain several at one. Further, they are limited to a size defined in the creation process and simply 'die' a painful death if they exceed this size.
Bottom line, LVM snapshots are fine for low duty file servers with few files changed and not many concurrent open files.

You can also use BTRFS which handles and performs much better. The drawback: The filesystem is relatively new. Though I had no problems with it for a few months now I would not use it for a production system yet.

If you like to implement the LVM or BTRFS snapshot system, I can further assist you.
Avatar of farzanj
As said above you can alias the rm command, so when you are calling rm, you are really calling another command or a script.

I had implemented a script.  For rm, I aliased to a script which would compress the file and move to a "RecycleBin" directory.  It would also save the location of the original file before moving.

Then undelete or unrm would uncompress it and move it back to its original location by checking the logs file that keeps track of all the files in the recycle bin.
alias rm 'mv $* "~/Recycle Bin"'
ASKER CERTIFIED SOLUTION
Avatar of Member_2_6582184
Member_2_6582184
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is very difficult to recover the data from deleted filesystem in linux, there is not  a direct way to restore deleted files, you need to use 3rd party tool.


Is there a way to automatically recover the files in "/lost+found" directory?
https://access.redhat.com/site/solutions/36632

How to recover a deleted file in ext3 filesystem?
https://access.redhat.com/site/solutions/24862

How to recover a deleted file on ext2 file system?
https://access.redhat.com/site/node/2214

How do I backup and restore a whole Red Hat Enterprise Linux system with the dump/restore commands?
https://access.redhat.com/site/solutions/17525
Avatar of mac_g

ASKER

while defining alias ..

what about the options like  ...-rf  while we define alias..