Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 986
  • Last Modified:

[ 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 -
0
mac_g
Asked:
mac_g
1 Solution
 
jeff_01Commented:
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
0
 
jeff_01Commented:
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
0
 
Daniel HelgenbergerCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
farzanjCommented:
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.
0
 
gheistCommented:
alias rm 'mv $* "~/Recycle Bin"'
0
 
Daniel HelgenbergerCommented:
To add a somewhat imported thing to the above comment: You need to create a '~/Recycle Bin' directory first and always make shure it exists. Otherwise your last deleted file would be moved to a file called 'Recycle bin' overwriting the previously deleted file.
Also it is somewhat inefficient when deleting files on other file systems then / or
/home respectively.
I suggest wiring a script witch takes care of the above cases.
(Pardon me, when using the shell I cannot imagine cases I would need such a thing as a recycle bin)
0
 
madunixChief Information Security Officer Commented:
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
0
 
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
while defining alias ..

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now