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!!

On Jun 19, 2008, at 10:43 AM, Scott K. wrote:

database.

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

What’s in db/schema.rb?

Scott K. 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.

George B. wrote:

On Jun 19, 2008, at 10:43 AM, Scott K. wrote:

database.

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

What’s in db/schema.rb?

This file is auto-generated from the current state of the database.

Instead of editing this file,

please use the migrations feature of ActiveRecord to incrementally

modify your database, and

then regenerate this schema definition.

Note that this schema.rb definition is the authoritative source for

your database schema. If you need

to create the application database on another system, you should be

using db:schema:load, not running

all the migrations from scratch. The latter is a flawed and

unsustainable approach (the more migrations

you’ll amass, the slower it’ll run and the greater likelihood for

issues).

It’s strongly recommended to check this file into your version control

system.

ActiveRecord::Schema.define(:version => 15) do

create_table “articles”, :force => true do |t|
t.string “title”
t.binary “body”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “attributes”, :force => true do |t|
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “comments”, :force => true do |t|
t.string “title”
t.string “body”
t.string “username”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “compound_materials”, :force => true do |t|
t.integer “compound_id”
t.integer “item_id”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “compound_types”, :force => true do |t|
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “compounds”, :force => true do |t|
t.integer “item_id”
t.integer “compound_type_id”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “item_types”, :force => true do |t|
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “items”, :force => true do |t|
t.integer “item_type_id”
t.integer “attribute_id”
t.integer “attribute_secondary_id”, :default => 0, :null => false
t.integer “wear_id”
t.integer “weapon_type_id”
t.string “image_name”
t.string “name”
t.string “description”
t.integer “rank”
t.integer “level”
t.string “manufacturable”
t.string “hp”
t.string “sp”
t.string “maxhp”
t.string “maxsp”
t.string “atk”
t.string “def”
t.string “mat”
t.string “mdf”
t.string “spd”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “manufacture_materials”, :force => true do |t|
t.integer “manufacture_id”
t.integer “item_id”
t.integer “required_num”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “manufactures”, :force => true do |t|
t.integer “item_id”
t.integer “tool_id”
t.integer “make_num”
t.integer “make_time”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “tools”, :force => true do |t|
t.integer “item_id”
t.integer “parent_id”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “users”, :force => true do |t|
t.string “login”
t.string “email”
t.string “crypted_password”, :limit => 40
t.string “salt”, :limit => 40
t.datetime “created_at”
t.datetime “updated_at”
t.string “remember_token”
t.datetime “remember_token_expires_at”
end

create_table “weapon_types”, :force => true do |t|
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end

create_table “wears”, :force => true do |t|
t.string “name”
t.datetime “created_at”
t.datetime “updated_at”
end

end

On Jun 19, 2008, at 10:54 AM, Scott K. wrote:

ActiveRecord::Schema.define(:version => 15) do

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

On 19 Jun 2008, at 18:03, julian wrote:

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

What were you backing up?

On Jun 19, 12:59 pm, Ar Chron [email protected]

Andrew F. wrote:

On Jun 19, 5:43�pm, Scott K. [email protected]
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

Yes!! I still have my development log! it’s 610 megs but it does
contain all the SQL statements. Now if i can just figure out how to
extract them and apply them to the database…hmmm.

On Jun 19, 5:43 pm, Scott K. [email protected]
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

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!

Scott K. wrote:

Andrew F. wrote:

On Jun 19, 5:43�pm, Scott K. [email protected]
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.