forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportDB
More file actions
executable file
·40 lines (30 loc) · 1.08 KB
/
importDB
File metadata and controls
executable file
·40 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env coffee
{ exec } = require 'child_process'
host = process.argv[2] or "localhost"
console.info "Trying to connect Mongo server at #{host}"
check = """ mongo #{host}/koding --quiet --eval="print(db.jGroups.count({slug:'guests'}))" """
exec check, (err, stdout, stderr)->
if err or= stderr
if err.code is 1
console.error "Failed to connect Mongo server."
console.info "You can pass different server address as first parameter."
else
console.error "An error occurred:", err
process.exit 1
else if stdout is "1\n"
console.warn "DB already exists, not importing at this time."
process.exit 0
else
exec """
if [[ -f ./install/custom-db-dump.tar.bz2 ]]; then
tar jxvf ./install/custom-db-dump.tar.bz2
else
tar jxvf ./install/default-db-dump.tar.bz2
fi
mongorestore -h#{host} -dkoding dump/koding
rm -rf ./dump
""", (err, stdout, stderr)->
console.log stdout
console.error stderr if stderr
console.info "DB didn't exists I created a blank one."
process.exit 0