Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Data Recovery (the Violent way)

Rails Data Recovery (the Violent way)

In this presentation, you'll learn how to recover Rails data from log file. This approach is database agnostic and could be adapted for many Rails apps.

Avatar for Trung Lê

Trung Lê

June 13, 2013

More Decks by Trung Lê

Other Decks in Programming

Transcript

  1. What to do? •Write down things to be done in

    checklist •Redirect to graceful warning page •Assure customer (white lies) •Backup existing slice •Work in pair Thursday, 13 June 13
  2. Concept log/ production.log Parser Mechanize Extract HTTP query params Mass-Replicate

    HTTP requests Identify needed HTTP request details Thursday, 13 June 13
  3. Request params extract •Could be huge in size ~ slow

    read •Contains ‘noise’ details •Could be generated with custom logger Thursday, 13 June 13
  4. Reduce the log size •Split into many small files with

    UNIX’s split •Scope the lines by timestamp Thursday, 13 June 13
  5. Clean up ‘noise’ •Assume you are using default Rails logger

    •Delete all but lines starting with: •Started GET|POST|PUT|DELETE •Parameters: {.*} •Sublime Text’s useful shortcut: •Ctrl + ⌘ + G •Shift + Ctrl + K Thursday, 13 June 13
  6. Main methods •login(): faux-authentication •make_call(): •Convert hash to HTTP Query

    params •Only perform HTTP request with mechanize Thursday, 13 June 13
  7. Ruby hash <-> HTTP params •mechanize use HTTP query hash

    •Should be able to convert nested hash for Rails `accepts_nested_attributes` Thursday, 13 June 13
  8. Lesson Learned •Backup before applying things on production •Backup two

    to three times a day •Asking for confirmation for any rake tasks on production •Teamwork makes difference! Thursday, 13 June 13