Creating backup of files being deleted


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Creating backup of files being deleted
# 1  
Old 01-05-2010
Creating backup of files being deleted

Hi All ,

We usually tend to use rm -f or rm -rf commands to delete files and directories in UNIX based Systems. But despite of utter care while deletion, there is high possibility that some of important files get deleted by mistake (as in the case of rm -f *).

So , one way to avoid this could be creating the backup of files deleted to some other directory. But for this , the execution of each rm -f and rm -rf command needs to be tracked.

So , can we devise any mechanism with the help of Shell Script or some other way that everytime rm -f or rm-rf command is executed , the files being deleted will be copied to some other directory ?
# 2  
Old 01-05-2010
Hi,
I know!
Make an alias for rm (and disable the true rm command just to be sure), so that instead of removing files and directories, You just move them to another place!

Smilie

Best regards,
Lakris

PS Hmmm, I think Il just might patent that... I can call it the "recycle can", or such like...
# 3  
Old 01-06-2010
That's how we did it 20 years ago on HP-UX. Create a recycle directory and move files there with an rm alias (making sure that everyone finds the alias first in their PATH). Then we created a clean-up job that ran in cron and emptied this directory once a week.

I got many a free lunch from a very happy programmer after he deleted an important directory or file. I'd always tell them there might be a way to get it back and make them sweat a day or so, then copy it back and be the hero.

Hey, you have to take it where you can get it. Smilie
# 4  
Old 01-06-2010
Long ago, I wrote a script that would cpio de files elsewhere to be archived in compressed format and cron job would run to delete the archives after 3- months...
# 5  
Old 01-06-2010
Thanks to all for replying. All replies were great.It is so simple to deal with problem.

Just an additional thing , I want to know how can we disable actual rm command of UNIX system so that every time I run rm command it would point to my alias only. Or just setting alias will take care of it.

Thanks a lot to all again Smilie

Last edited by swapnil.nawale; 01-06-2010 at 02:06 PM..
# 6  
Old 01-06-2010
rm's used by scripts, not just interactive things, so you'd better leave it alone. Imagine your backup dir filling up with temp files! Smilie An alias lets you manage rm only for interactive users; plus if they really, genuinely need the real rm they can call it with its absolute path.

Last edited by Corona688; 01-06-2010 at 02:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Needed for creating the folder by checking today's date and, take backup using rsync command

How to create a shell script to create a folder by using the today's date to take backup using rsync command on every evening around 7 pm. Kindly help. Thanks. To be more precise, I want to create a script which matches the today's date with server's date format, if matches then creates the... (2 Replies)
Discussion started by: bakula10
2 Replies

2. Solaris

Need help in creating script for disk mirror and backup

Hi, I am very new to scripting. I need to create a script which does following. Scenario: First get the format command output echo | format Insert the new disk to Solaris Server Get Zpool status format the new disk ( Here I need to select the new disk which have been inserted, I do... (1 Reply)
Discussion started by: praveensharma21
1 Replies

3. UNIX for Dummies Questions & Answers

Creating a backup of UNIX--Need help

My company has a client that has mostly windows machines but has 1 Unix machine(still trying to find out what version..Solaris, AIX, etc) and they want me to do a full backup of this Unix machine and store it on one of their windows servers. Is there a not too difficult way of doing this? ... (1 Reply)
Discussion started by: seanbl
1 Replies

4. UNIX for Dummies Questions & Answers

BackUp Home/Creating User from File

Hi! I want to test something to learn Shell scripting better. 1) How can I make a BackUp from all users and groups homedirectory? I want to save that backup in an archiv. Can I choose how to name the backUp archiv? 2) Ok I want to make a file like csv, in this file are listed Users.... (3 Replies)
Discussion started by: CommanderLinux
3 Replies

5. AIX

Who deleted my files

Just looking for some guidance on how to figure out who might have deleted some files off one of my systems. These files are not root owned files so could be deleted by a handful of folks in the group responsible for these files besides the root users. Anyway I have been tasked with trying to... (1 Reply)
Discussion started by: juredd1
1 Replies

6. Linux

Need help with deleted files

Hello. I am having a problem and I was wondering if I could get some help from here. I changed into a directory with the cd command and I wanted to delete a folder and all of its subdirectories, so I went ahead and did a rm --recursive * in my current directory to realize that I was in the wrong... (3 Replies)
Discussion started by: jonnydadesigner
3 Replies

7. Shell Programming and Scripting

Need to Recover Deleted Files

Hi, By mistake, executed the following command : rm -rf * and ALL files got deleted. But I need to get back these files as they are very very important. Please help me how to recover this file. Its Urgent for me please. Thanks in advance. (6 Replies)
Discussion started by: unx100
6 Replies

8. UNIX for Advanced & Expert Users

deleted all files - rm *

Hi All, I am using Fedora Core and Windows Xp. I deleted all the files from root directory. When i am trying to restart the computer it showing some grub > prompt. What i will do ? I have lots of data in XP OS. Please help me i used # rm * (8 Replies)
Discussion started by: pritish.sas
8 Replies

9. Shell Programming and Scripting

Finding deleted files

One of the files got deleted and i want to find who deleted that file. I think we can get the list using history command. Could you please let me know how to get the list of rm commands from history and who previously logged in and did that? Any other suggestions other than history also... (2 Replies)
Discussion started by: Krrishv
2 Replies

10. Solaris

creating log files for a backup script on solaris

I have a simple backup script that I am running to back up drives across the network. However I need to have detailed log files for this script such as time backup started, what was backed up, if there were any errors and the time that the backup was complete. I would also like the script to... (3 Replies)
Discussion started by: valicon
3 Replies
Login or Register to Ask a Question