Live data from Hacker News

I Accidentally Deleted All Our Data

taylor.fausak.me

31–40 of 78 posts

Re: I Accidentally Deleted All Our Data

#32

Happy to hear that you had backups and not too much data was lost because you caught it quickly. But besides the obvious takeaway of always having recent, tested backups, I think it's also important to get out of the habit of ever using a REPL (or SSH for that matter) to connect to production servers. Write a one-off script, document when and why you made it, check it into your VCS of choice, and run it against the t…

I usually write my scripts in a temporary file and run them through Django with something like: $ python manage.py shell In this instance, I didn't even consider that what I was doing could be catastrophic. But you're right, you want to avoid doing things manually. In the future, I'll track all the scripts I run. And thanks for the tip about Fabric, I'll check it out.

For bonus points, clone your production db locally and test your script against it a few times first.

Or, you know, have a staging server.

Re: I Accidentally Deleted All Our Data

#34
A long time ago I once had a "rm -Rf ..." in a bash script. Missed a space, and yep, it deleted everything. Luckily the DB wasn't owned by the logged-in user so everything was recoverable. One of these "learning the hard way" examples of what NOT to put in a script (this may sound all very obvious but when you're in a hurry, really stupid mistakes do happen).

Re: I Accidentally Deleted All Our Data

#35

Who works with a prod database in an interactive interpreter? My eyes are literally wide in shock.

I do this from time to time. But I also type "BEGIN" before anything else.

Watch out for database locks if you do this.

I once opened a transaction, did an ALTER TABLE, and the site hung until I either committed or rolled back the transaction.

Re: I Accidentally Deleted All Our Data

#36

OUCH. Doesn't django let you check if models are valid without saving them? In rails I can do: Family.all.select {|f| !f.valid?}

Django offers a validate function that does exactly that. Unfortunately, the email uniqueness constraint is handled in our save function, due to some backend complexity. So it wouldn't have helped here. Plus, it was a typo that caused the problem, not the function :)

Re: I Accidentally Deleted All Our Data

#37

Who works with a prod database in an interactive interpreter? My eyes are literally wide in shock.

It depends, if you're working with a smaller database with a smaller team with a smaller client base, there's not as much harm. There could possibly be more harm in having more ceremony for doing simple things.

Re: I Accidentally Deleted All Our Data

#38

"We had a backup from earlier in the week" week? That seems kind of off. I'd suggest setting up backups more often than that, especially for production data. Sorry to hear about that. I destroyed a drive once a long time ago (~1994) as well. Happens to the best of us.

Because of this, we're going to back up parts of our database more frequently. A lot of our data isn't mission critical, so it wouldn't make sense to do daily backups for it. Other things, like family accounts, obviously are. We're going to back those up daily from here on out.

I'm not too paranoid but we have, at least, transaction logs, replicated backup server, nightly offsite backup of transaction logs, and twice monthly full backups. That covers a lot of failure cases and isn't too much to transfer. Transaction logs are a godsend -- you could have even found out what you did wrong.

Even non-mission critical data loss can be bad.

Re: I Accidentally Deleted All Our Data

#39
Postgresql has PITR backup. http://www.postgresql.org/docs/9.1/static/continuous-archivi...

This allows you to go back in time to an earlier snapshot of your data, without having to do a full database backup.

Unfortunately, it's still a pain to setup, even with tools like https://github.com/greg2ndQuadrant/repmgr. Wish there was more convention over configuration.

(I use Heroku's WAL-E to backup the data to S3. https://github.com/heroku/WAL-E)

Re: I Accidentally Deleted All Our Data

#40

Earlier quoted context omitted.

I usually write my scripts in a temporary file and run them through Django with something like: $ python manage.py shell In this instance, I didn't even consider that what I was doing could be catastrophic. But you're right, you want to avoid doing things manually. In the future, I'll track all the scripts I run. And thanks for the tip about Fabric, I'll check it out.

For bonus points, clone your production db locally and test your script against it a few times first. Or, you know, have a staging server.

Exactly.

This is the reason why enterprises always use staging servers with test suites.

It is irrelevant if you use NoSQL, SQL, or magic, if you don't have development+staging+production platforms for a business reliant on an information system, you're doing it wrong and it will bite you hard eventually.

Post reply on HN