Live data from Hacker News

Ooops.

github.com

161–170 of 247 posts

Re: Ooops.

#161
post #127

Earlier quoted context omitted.

DELETE FROM? Try TRUNCATE TABLE CUSTOMER ... that one skips the transaction log too, no ROLLBACK possible.

You can't accidentally write a TRUNCATE statement though.

You can have dev-environment scripts that accidentally point to a production instance.

Re: Ooops.

#162
post #84

Earlier quoted context omitted.

Over the years I've been steadily training myself to type "WHERE" earlier in the process, until I have finally settled on the obvious-in-hindsight solution: Always simply start with the WHERE clause. (Of course every effort not to be on the SQL shell of a production server in the first place should be taken, but sometimes you need a sledgehammer and nothing else will work.)

The habit I learned was: before running any DELETE or UPDATE statement, run a SELECT with the same WHERE. (e.g. if I meant to say DELETE FROM puppies WHERE cute = 0, first run SELECT FROM puppies WHERE cute = 0.) I find I remember to do that because of the direct benefit (getting a sneak preview of what I'm going to delete), but it also means I end up thinking twice about the WHERE statement, so I'm much less likely…

I do the same thing. Not sure that it has ever saved me from a disaster, but I do like the sneak peak and am DELETE FROM disaster free. knocking on my desk

Re: Ooops.

#163
I've done a similar thing a few years ago when I was first starting work on my guild hosting company's code.

At the time, the main thing hosted on that machine was my WoW guild's website, which I had been working on for close to a year, and was beginning work on converting the site over to a general purpose guild hosting site.

I was doing some work for a client, setting up a mirror of sorts for some kind of yearbook thing I had built for them. For that, I made a script that would mirror the online yearbook with wget, zip up the whole directory, then clear out the mirrored pages (all I cared to store and serve was the zip file).

All of my websites were stored in /www on the server, and the raw yearbook was located at /www/clientname/www. Inside the clientname directory, I had the mirror script which was something like this:

  wget -whatever_options http://whatever.address www
  zip yearbook.zip www
  rm -fr /www
Unfortunately, because of how frequently I type / before www to get to my web dev directory, I instinctively put "/www" in the script where I just wanted to do "www". I ran the script, checked to make sure and it looked good, and deployed it to a cronjob.

My heart sank when I tried loading my guild page a few minutes later (just to see what was going on on the forum, if anything), and it served up a bunch of 404s.

I went to /www/guildsite and saw it completely empty, and almost immediately figured out what had happened. At that point, I had to get my composure and figure out what I was going to do (I did not have backups or source control). I unmounted the directory, and went off to lunch with a friend, shaking with anxiety.

Upon return, I started writing out a perl script to scour the device byte for byte looking for PHP scripts, looking for instances of I had to manually go through every file (which were named numerically in the order they were found in the filesystem) and determine if it was the most recent (or recent enough) copy of the code, clear off any trailing bytes, and rename it to the filename it used to have. Luckily I could remember the name of almost every file in the system. It took about 8 hours to go through the few hundred files and recover them.

Needless to say, I learned my lesson after that, but the feeling of victory I got from recovering those files from the device was epic.

6 years later, I realize that that's a rather trivial thing to do, but at the time, I didn't know what I was going to do, and remembering that the file system doesn't clear all the bytes of the a file just it's reference gave me tons of hope.

Re: Ooops.

#164

Earlier quoted context omitted.

It's like reading Youtube comments--not for the faint of heart. And the jab at reddit from the HN pedestal is probably misguided... reddit used to be more like HN, and HN is becoming more like the bad parts of reddit every day. Every site tends toward Youtube level comments as time passes, and the people who don't like it eventually jump ship to a new site, and then the process repeats itself.

HN is not at all like the 'bad parts' of Reddit.

In the discussion on PDF in JavaScript yesterday, this document was linked in an HN comment: http://crocodoc.com/EfqW081

I wonder if the only saving grace of HN is that it's not completely anonymous.

Re: Ooops.

#166

This terrifies me now of every single install script that refuses to run if not root.

With a bug like this, an install script without root permissions can still wipe out your $HOME when messing around in the dotfiles. Scary!

That is why I keep a second home directory, /home/experimental for trying things out.

Re: Ooops.

#167
post #60

Never use rm's -f flag while operating as the root user. Never. Replace with -i until you are absolutely 100% certain the script you're writing works as expected. Always doubt yourself; be humble.

The -I flag is a bit more friendly; one may safely alias rm to rm -I and not even notice on the common case (deleting a single file).

I use a script that moves a file to a ~/.trash directory when I use rm. If I am sure I want to actually delete a file permanently I just use /bin/rm.

Re: Ooops.

#169
post #79

Is there a good reason why Linux doesn't have a recycle bin?

Mine does, now. I have a directory ~/.trash and a script rm that moves files to the trash. If I really want to permanently delete something I need to use /bin/rm (including for cleaning out my .trash dirs).

ADDED: Note that I have a .trash in each user's home directory including /root. And a copy of the rm script in each user's home/bin.

Re: Ooops.

#170

Earlier quoted context omitted.

The habit I learned was: before running any DELETE or UPDATE statement, run a SELECT with the same WHERE. (e.g. if I meant to say DELETE FROM puppies WHERE cute = 0, first run SELECT FROM puppies WHERE cute = 0.) I find I remember to do that because of the direct benefit (getting a sneak preview of what I'm going to delete), but it also means I end up thinking twice about the WHERE statement, so I'm much less likely…

I do that for 'rm'. I do an 'ls' first, then reedit the command and put an 'rm'.

Ooh! I'm going to start doing that.
Post reply on HN