Skip to content

Commit f7b1ba7

Browse files
committed
Merge pull request #3 from UCSD-TIES/dbdump
Dbdump
2 parents 6fc8b27 + ffa2b39 commit f7b1ba7

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

scripts/dbdump.coffee

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Description:
2+
# A script that allows hubot to make a dump of the database and send it to a public access folder.
3+
#
4+
# Dependencies:
5+
# SSH2 (https://github.com/mscdex/ssh2)
6+
#
7+
# Configuration:
8+
#
9+
# Commands:
10+
# hubot dbdump stage - creates a dump of the db from the staging database
11+
# hubot dbdump prod - creates a dump of the db from the production database
12+
ConnectServ = require("ssh2")
13+
14+
module.exports = (robot) ->
15+
robot.respond /dbdump\s?(.*)?/i, (msg) ->
16+
if msg.match[1] == 'stage'
17+
version = 'stage'
18+
envhost = process.env['STAGING_SSH_HOST']
19+
envport = process.env['STAGING_DB_SSH_PORT']
20+
envuser = process.env['STAGING_DB_SSH_USER']
21+
envprivatekey = process.env['PRIVATEKEY']
22+
23+
if msg.match[1] == 'prod'
24+
version = 'prod'
25+
envhost = process.env['PROD_SSH_HOST']
26+
envport = process.env['PROD_DB_SSH_PORT']
27+
envuser = process.env['PROD_DB_SSH_USER']
28+
envprivatekey = process.env['PRIVATEKEY']
29+
30+
moo = ""
31+
c = new ConnectServ()
32+
c.on "connect", ->
33+
34+
c.on "ready", ->
35+
c.exec "pg_dump whwn | gzip > whwn.gz; scp whwn.gz [email protected]:~/public_html/whwn.gz", (err, stream) ->
36+
throw err if err
37+
stream.on "data", (data, extended) ->
38+
console.log ((if extended is "stderr" then "STDERR: " else "STDOUT: ")) + data
39+
moo = data.toString('utf-8')
40+
41+
stream.on "exit", (code, signal) ->
42+
c.end()
43+
44+
c.on "error", (err) ->
45+
console.log "Connection :: error :: " + err
46+
47+
c.on "end", ->
48+
console.log "Connection :: end"
49+
50+
c.on "close", (had_error) ->
51+
console.log "Connection :: close"
52+
msg.send moo
53+
msg.send "DB Dump Complete, download at dev1.churenshao.com/~robot/whwn.gz"
54+
55+
c.connect
56+
host: envhost
57+
port: envport
58+
username: envuser
59+
privateKey: envprivatekey

scripts/status.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
# Configuration:
88
#
99
# Commands:
10-
# hubot status - replies with uptime of staging (for now)
10+
# hubot status stagedb - Status of staging DB
11+
# hubot status stagepy - Status of staging Python
12+
# hubot status stageq - Status of staging Queue
13+
# hubot status stageworkers - Status of staging workers
14+
# hubot status proddb - Status of production DB
15+
# hubot status prodpy - Status of production Python
16+
# hubot status prodq - Status of production Queue
17+
# hubot status prodworkers - Status of production workers
18+
1119
ConnectServ = require("ssh2")
1220

1321
module.exports = (robot) ->
@@ -67,7 +75,7 @@ module.exports = (robot) ->
6775
c.on "connect", ->
6876

6977
c.on "ready", ->
70-
c.exec "uptime", (err, stream) ->
78+
c.exec "top -n 1 -b", (err, stream) ->
7179
throw err if err
7280
stream.on "data", (data, extended) ->
7381
console.log ((if extended is "stderr" then "STDERR: " else "STDOUT: ")) + data

0 commit comments

Comments
 (0)