You are not logged in.

#1 2006-05-11 20:36:35

Infracephas
Member
From: Mint Hill, NC
Registered: 2005-11-25
Posts: 34
Website

Protect a Directory from Deletion.

Hi all,

I have a directory, "stuff" that contains four years accumulation of organized and categorized files (mp3's, writings, programs, movies, etc.).  This particular directory resides in my home directory.

It occured to me that it would be very simple to accidentally type, "rm -rf stuff,"  it would all be over.

How can I protect that directory from being accidentally deleted by me? (without inhibiting me from moving files into it, writing to files in it, executing files in it, etc).

As the old saying goes, if you put all your eggs in one basket, watch that basket.


Russ

Offline

#2 2006-05-11 20:56:04

Titus
Member
From: Izmir
Registered: 2006-05-11
Posts: 120
Website

Re: Protect a Directory from Deletion.

you can exist that directory when u are root so when you are a normal user you can't delete it.it is the simplest way.


In a world without walls,who need windows?

Offline

#3 2006-05-11 21:07:45

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Protect a Directory from Deletion.

I would just go with the backup route. Anyone running a computer should do it anyways just because anything could happen. I back up /home, /etc and some other miscallaneous stuff everynight as a cronjob onto a separate hard drive in a tarball. Its saved me at least three or 4 times now in some shape or form in the last year.

Offline

#4 2006-05-11 22:03:50

nuggien
Member
Registered: 2006-05-05
Posts: 11

Re: Protect a Directory from Deletion.

write a wrapper "rm" script that checks the directory name before passing it on to the real "rm" binary in /bin/rm

Your rm script can just make sure the directory name isn't one of your precious folders.  If it is, it just prints a warning message of some sort.

#!/bin/bash

if [ $1 = "stuff" ]; then
        echo "sorry, can't rm"
        exit
fi

/bin/rm $1

That's just a 5 second example I typed up.  Probably want to add a $2 in there to be able to pass stuff like "-rf" too.  Just alias that to be rm instead of the real rm.[/code]

Offline

#5 2006-05-12 19:45:44

Infracephas
Member
From: Mint Hill, NC
Registered: 2005-11-25
Posts: 34
Website

Re: Protect a Directory from Deletion.

Thanks for the suggestions.  I like the backup solution, but I'm not going to go there just yet.  The directory is too big for that.  In the future (next month) I might set up a a separate machine to automatically backup for me.

I'm not sure what "exist" means, but that sounds like it might be the best solution.  Could you please explain what that means?

If that doesn't work out, I'll write a wrapper (neat idea).

Thanks.


Russ

Offline

#6 2006-05-12 22:37:10

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Protect a Directory from Deletion.

backup to a CD, also, a remote server with version control may be nice - typically server people do nightly backups.  I keep all my configs on a remote server, under svn

Offline

#7 2006-05-12 22:46:30

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: Protect a Directory from Deletion.

Maybe man chattr and man lsattr will help (ext2/3 only afaics).

Offline

#8 2006-05-13 00:37:09

slackhack
Member
Registered: 2004-06-30
Posts: 738

Re: Protect a Directory from Deletion.

backup is one of the first things you should do, not one of the last. wink i back up /etc, /home and a mounted "media" directory that sounds just like your stuff directory to another hard disk every night, and just like with Penguin that has saved me -big time- at least a couple times. selected really important stuff i back up to CD also. if the directory is really big, you can use something like bzip to really compress it. believe me, backing up is definitely worth it.

Offline

#9 2006-05-13 02:54:59

droog
Member
Registered: 2004-11-18
Posts: 877

Re: Protect a Directory from Deletion.

I agree with the backup, i would be more worried about a harddrive or filesystem failure than accidentally typing rm -r ~/stuff. that seems like a difficult mistake.

Offline

#10 2006-05-13 03:03:39

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: Protect a Directory from Deletion.

droog wrote:

I agree with the backup, i would be more worried about a harddrive or filesystem failure than accidentally typing rm -r ~/stuff. that seems like a difficult mistake.

Err.. see almost every post in this thread.  lol

Offline

#11 2006-05-13 04:43:49

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: Protect a Directory from Deletion.

I svn /home/codemac

Offline

#12 2006-05-13 08:07:41

tomfitzyuk
Member
Registered: 2005-12-30
Posts: 89

Re: Protect a Directory from Deletion.

How long would it take to:
- bzip
- gzip

250GB on a SATAII then copy to a USB2.0 hard drive (AMD 3200+)?

Basically, would I be able to back up 250GB within 8 hours?

Also, if I'm archiving my home directory overnight, whilst I'm downloading files how would this be dealt with? I guess it has something to do with my filesystem: ext3.

Offline

#13 2006-05-13 10:29:47

phildg
Member
Registered: 2006-03-10
Posts: 146

Re: Protect a Directory from Deletion.

I would advise against replacing a real command with an alias. The reason being if for some reason (and there are many) the alias doesn't exists when you think it does, so you think your're safe doing rm -rf stuff but in actual fact you've just deleted all your important files.

One thing you can do is implement a rudimentary 'recycle bin'. Choose a name that isn't a real command on your system. 'del' might be a good one and alias that to `mv "$@" ~/.Trash`.

IMHO, by far the best thing to do is implement a backup system. The particular method I implement doesn't require much more space than the files your backing up unless your continously changing, deleting creating hundreds of files. A howto that I based my backup implementation on can be found here: http://www.mikerubel.org/computers/rsync_snapshots/

Edit (to answer some of your questions):

When your downloading stuff (of the internet I presume) then the speed of your internet connection is typically much slower than that of disk IO, so it shouldn't effect it much. Typically when the backup script reaches the file that your downloading it will just backup the partially downloaded file, or thats whats happened in my experience.

bzip will take much longer than gzip, though I can't really say how long it would take to back up 250 gigs worth, 8 hours sounds a reasonable estimation, to me anyhow.

Offline

#14 2006-05-13 11:50:48

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Protect a Directory from Deletion.

You only have to backup the whole stuff of 250 GB once. After that, you may use rsync to only write the diffs to your backup dir!

May take some time with 250 gigs and depends on the type of files you have there, if it is like the pacman-db (maaaany small files) it may take longer but probably not 8 hours

Offline

#15 2006-05-13 15:02:36

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: Protect a Directory from Deletion.

I've made many large drive images with ghost on internal (ide/sata) and external USB2 disks.

With IDE ATA133 or SATA drives i achieve get 50-60 GiB per hour minute, USB2 however only manages 20-30 Gib per hour.
A lot will depend on how well your data compresses.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#16 2006-05-14 01:22:39

iBertus
Member
From: Greenville, NC
Registered: 2004-11-04
Posts: 2,228

Re: Protect a Directory from Deletion.

Why backup your entire home directory? Surely not everything there is important. Only backup what you cannot replace or what is a huge pain in the ass to replace. DVD-RWs are great for backing up important data, but may become too much trouble with massive directories (250GB! holy shit).

Why not just use RAID? If the data is truely important and cannot be replaced then you should utilize some form of redundant disk array. Internal hard drives and IDE/SATA raid controllers are very cheap now, so this is more of an option to everyone than a few years back.

Offline

Board footer

Powered by FluxBB