-
-
Save jashkenas/1130537 to your computer and use it in GitHub Desktop.
Revisions
-
jashkenas revised this gist
Aug 7, 2011 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ fs = require "fs" path = require "path" rimraf = require "rimraf" {spawn} = require "child_process" url = require "url" heroku = config: (callback) -> @@ -13,7 +13,7 @@ heroku = raw += data child.on "exit", (code) -> console.log "heroku config exit: #{code}" if code isnt 0 config = {} pattern = /^([^=]+)=(.*)$/gm @@ -39,15 +39,15 @@ task "db:pull", "Grab a copy of the production DB.", -> console.log "rimraf: #{err}" if err spawn("mongodump", args).on "exit", (code) -> console.log "mongodump exit: #{code}" if code isnt 0 args = ["local-dev", "--eval", "db.dropDatabase()"] spawn("mongo", args).on "exit", (code) -> console.log "mongo exit: #{code}" if code isnt 0 args = ["--drop", "--db", "local-dev", path.join(dir, db)] spawn("mongorestore", args).on "exit", (code) -> console.log "mongorestore exit: #{code}" if code isnt 0 rimraf dir, (err) -> console.log "last rimraf: #{err}" if err -
jbarnette renamed this gist
Aug 7, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jbarnette created this gist
Aug 7, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ fs = require "fs" path = require "path" rimraf = require "rimraf" spawn = require("child_process").spawn url = require "url" heroku = config: (callback) -> child = spawn "heroku", ["config", "--shell"] raw = "" child.stdout.on "data", (data) -> raw += data child.on "exit", (code) -> console.log "heroku config exit: #{code}" unless code == 0 config = {} pattern = /^([^=]+)=(.*)$/gm config[m[1]] = m[2] while m = pattern.exec raw callback config task "db:pull", "Grab a copy of the production DB.", -> heroku.config (cfg) -> dbURL = url.parse cfg.MONGOHQ_URL db = dbURL.pathname.substr 1 dir = "tmp/mongodump" host = dbURL.hostname port = dbURL.port [username, password] = dbURL.auth.split ":" args = ["--host", host, "--port", port, "--db", db, "--username", username, "--password", password, "--out", dir] rimraf dir, (err) -> console.log "rimraf: #{err}" if err spawn("mongodump", args).on "exit", (code) -> console.log "mongodump exit: #{code}" unless code == 0 args = ["local-dev", "--eval", "db.dropDatabase()"] spawn("mongo", args).on "exit", (code) -> console.log "mongo exit: #{code}" unless code == 0 args = ["--drop", "--db", "local-dev", path.join(dir, db)] spawn("mongorestore", args).on "exit", (code) -> console.log "mongorestore exit: #{code}" unless code == 0 rimraf dir, (err) -> console.log "last rimraf: #{err}" if err