xargs is powerful; rm is dangerous.
I haven't slept much in the last few weeks as usual. Last night I slept for
about 75 minutes. I've been awake since 11:15 last night.
Earlier this evening I unpackaged a tarball containing my public_html directory
from Stevens. I did this in the wrong directory and it dumped its contents into
my public_html here on this machine. I realized I was an idiot.
I had the brilliant idea of using the -t option of tar and piping that output
to rm. I was puzzled at first and then I realized I was an idiot again and
rm does not work that way. I'd like to remind everyone that I had less than
an hour and a half of sleep and had been awake for more than 20 hours at this
point. At 7:55 I had the brilliant idea of using xargs to take the output of
tar and turn that into command line arguments for rm. This worked, but it
left a bunch of empty directories behind. I didn't want to go though manually
to look for the empty ones and delete them by hand. I had a
brilliant
idea. I'd just run the previous command with a -r option on rm. At 7:57 I
realized I was an idiot. Again.
I quickly opened up the man page for restore(8) and prayed that dump(8) had
actually worked for the nightly back ups. For months I have been using dump
to back up the primary disk in the machine to a (hardware) RAID 1 on a weekly
cycle of levels 0 through 6 starting on Sunday. I had never actually tried
a restore until tonight. Yes I realized this also made me an idiot.
Long story short (too late) I was able to restore the data with the level 4
from last night and the level 0 from Sunday. I used pax to copy the data from
the restore point back to where it belongs which preserved the file dates.
So, like most lessons dealing with computers, I learned something new today
by breaking it first, then having to fix it.
xargs is powerful; rm is dangerous, part 2
The first stupid command:
mforde@tak:~> tar -xzf webbing.tar.gz
The second stupid command that didn't work:
mforde@tak:~> tar -tzf webbing.tar.gz | rm
The command I should have stopped with
mforde@tak:~> tar -tzf webbing.tar.gz | xargs rm
The stupid command that deleted public_html and all of its contents
mforde@tak:~> tar -tzf webbing.tar.gz | xargs rm -r
The commands that saved me:
mforde@tak:/mnt/s1> restore -i -h -v -f 2007_09_16-level0
mforde@tak:/mnt/s1> restore -i -h -v -f 2007_09_20-level4
mforde@tak:/mnt/s1> mkdir ~/public_html
mforde@tak:/mnt/s1> cd ./usr/home/mforde/public_html/
mforde@tak:/mnt/s1/usr/home/mforde/public_html/> pax -rwvpe . /usr/home/mforde/public_html/
From the man page for restore:
-i This mode allows interactive restoration of files from a dump.
After reading in the directory information from the dump, restore
provides a shell like interface that allows the user to move
around the directory tree selecting files to be extracted. The
available commands are given below; for those commands that
require an argument, the default is the current directory.
In interactive mode, the commands I found very useful were ls, cd, add,
extract. ls and cd do exactly what they do in a regular shell. add added its
given argument to the list of files to be restored and extract starts the
restore of those files.