HELP i think i just lost my database forever!

I accidentally ran

rake

by itself and it started shooting a bunch of things across the screen and erased my database data!

I think it's because i have prod, dev, and test all pointing to the same database.

I thought i was doing full backups with mysql every night but it appears i forgot to select the schema.

wow i just lost a month worth of work. is there any way to recover this?

i'm running redhat linux es3. i need to undelete!!

What's in db/schema.rb?

George Bailey wrote:

Scott Kulik wrote:

I think it's because i have prod, dev, and test all pointing to the same database.

Ouch!!! And whatever possessed you to do that!

I assume you've verified that it really is gone, with MySQL admin or command line or something if you aren't using MySQL...

The database is easily constructed from your migrations. Your data, however, is another story... bit bucket heaven I fear.

What were you backing up?

So there's your schema. Between that and your schema-less backups you ought to be able to piece it together.

What were you backing up?

Scott Kulik wrote:

I think it's because i have prod, dev, and test all pointing to
the same database.

Ouch!!! And whatever possessed you to do that!

I assume you've verified that it really is gone, with MySQL admin or command line or something if you aren't using MySQL...

The database is easily constructed from your migrations. Your data, however, is another story... bit bucket heaven I fear.

And next time, take note of the comment in database.yml:

# Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production.

Fred

I accidentally ran

rake

by itself and it started shooting a bunch of things across the screen and erased my database data!

The default action for rake is to run tests, so it cleared out your DB in order to load the test fixtures.

wow i just lost a month worth of work. is there any way to recover this?

The log files should still be intact, and assuming you've been running in development mode all this time and not cleared them, the development log should contain all the SQL statements ever generated. In theory you can extract the SQL in order to replay it with a very good knowledge of regular expressions, grep, sed, and the like.

Regards, Andrew

Andrew France wrote:

Scott Kulik wrote:

Andrew France wrote:

I accidentally ran

rake

by itself and it started shooting a bunch of things across the screen and erased my database data!

The default action for rake is to run tests, so it cleared out your DB in order to load the test fixtures.

wow i just lost a month worth of work. �is there any way to recover this?

The log files should still be intact, and assuming you've been running in development mode all this time and not cleared them, the development log should contain all the SQL statements ever generated. In theory you can extract the SQL in order to replay it with a very good knowledge of regular expressions, grep, sed, and the like.

Regards, Andrew

Thanks for that tip. I was able to extract and parse all the SQL statements with using grep and some regular expressions in perl.

I was able to recreate my main table.

The only issue though is that I had a couple other tables with a few hundred records with some foreign keys to the main table which were all messed up since I did some manual database editing for some of the main entries.

But, alas the site is back up and running halfway back to normal. Your suggestion saved me about 40 hours of work and a lot of other people some grief.

thanks again.

And next time, take note of the comment in database.yml:

# Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'.

# Do not set this db to the same as development or production.

Did someone set the db to the same as development and production?

And did someone develop for a month without once writing a unit test?

And is someone running a live site without a backup policy?

Phlip wrote:

And next time, take note of the comment in database.yml:

# Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'.

# Do not set this db to the same as development or production.

Did someone set the db to the same as development and production?

And did someone develop for a month without once writing a unit test?

And is someone running a live site without a backup policy?

yup! I just started using rails about a month ago so my knowledge in some areas is pretty limited.

i guess i need to find a way to sync the test and production databases...thats the reason i was using production and development as the same database...and test unfortunately. i did however miss the the comment in the database.yml that running rake will erase the test database. i just wanted to get the syntax so i could roll back my last database migration. that's the last time i do that!

i started looking over unit tests but they looked pretty complicated on my first pass during my first week of learning rails.

i did have nightly backups running...but apparently i forgot to select the schema that i ended up losing.

my site actually is just an item database for an online game...nothing special.

http://wl.kuliksco.com if you want to take a peek.

so....at least i didn't lose any production data.

the scary part is that i'm a unix admin that handles the backups for all our 80 servers!! don't tell my boss!