scalingo_databases_rake_tasks 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 373be3441179822120599f7aa99842d5f68607fe
|
4
|
+
data.tar.gz: 76db07ab5d36be40a3739f88d752568663b0de3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a7ed16cfb52bf232c304f0ee269d80f10a75411396a39f489ed46d966bd55a90cf542a57588fd2ddd7c00fe20162ead351260e7171a5d2dc991e50ef660f73
|
7
|
+
data.tar.gz: ab9a12e9cea2fe2be89b1bd42399bcc6f0ab67ff0df8df1deea62fa0b911e0ba47fe1eef3846a8fa69934f61c33e08f2e76ed184f007f1722eda7bcbd6596c06
|
data/README.md
CHANGED
@@ -17,6 +17,20 @@ Available tasks for **each** database:
|
|
17
17
|
|
18
18
|
For remote operations you will have to set your shell's environment variable `APP` as your app name on Scalingo. The variable `DB_ENV_NAME` is optional, by default it will be the one generated when you provisionned the database addon. For example, if your database is a MongoDB then the variable will be `SCALINGO_MONGO_URL`.
|
19
19
|
|
20
|
+
### Available Env Vars
|
21
|
+
|
22
|
+
Global:
|
23
|
+
- `APP`: Scalingo app name (mandatory)
|
24
|
+
- `DB_ENV_NAME`: Scalingo database connection var name, e.g. `SCALINGO_MONGO_URL` (optional)
|
25
|
+
- `SSH_IDENTITY`: specify a SSH identity file, e.g. `~/.ssh/id_rsa` (optional)
|
26
|
+
|
27
|
+
MongoDB:
|
28
|
+
- `FILE`: your database config file name, e.g. `database` (optional)
|
29
|
+
|
30
|
+
PostgreSQL:
|
31
|
+
- `PG_DUMP_CMD`: specify the path or command name of the tool to use, default: `pg_dump` (optional)
|
32
|
+
- `PG_RESTORE_CMD`:specify the path or command name of the tool to use, default: `pg_restore` (optional)
|
33
|
+
|
20
34
|
### Commands
|
21
35
|
|
22
36
|
To see the complete list of tasks: `rake -T scalingo`
|
@@ -25,17 +25,30 @@ namespace :scalingo do
|
|
25
25
|
FileUtils.mkdir_p 'tmp'
|
26
26
|
end
|
27
27
|
|
28
|
+
def app_exists? app
|
29
|
+
`scalingo apps | grep " #{app} "`
|
30
|
+
$?.success?
|
31
|
+
end
|
32
|
+
|
28
33
|
def remote_credentials app, variable
|
34
|
+
unless app_exists? app
|
35
|
+
abort "*** App #{app} does not exists."
|
36
|
+
end
|
37
|
+
|
29
38
|
output = `scalingo -a #{app} env | grep "^#{variable}=" | cut -d '=' -f2 | tr -d '\n'`
|
30
39
|
uri = URI(output.strip)
|
31
40
|
if uri.to_s.blank?
|
32
|
-
|
41
|
+
abort "*** Environment variable #{variable} not found."
|
33
42
|
else
|
34
43
|
[uri.path[1..-1], uri.user, uri.password]
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
47
|
def start_scalingo_tunnel app, variable
|
48
|
+
unless app_exists? app
|
49
|
+
abort "*** App #{app} does not exists."
|
50
|
+
end
|
51
|
+
|
39
52
|
if ENV['SSH_IDENTITY']
|
40
53
|
cmd = "scalingo -a #{app} db-tunnel -i #{ENV['SSH_IDENTITY']} -p 27717 #{variable}"
|
41
54
|
else
|
@@ -96,10 +109,10 @@ namespace :scalingo do
|
|
96
109
|
app = ENV["APP"]
|
97
110
|
variable = ENV["DB_ENV_NAME"] || default_env_name
|
98
111
|
unless app
|
99
|
-
abort "Environment variable APP not found."
|
112
|
+
abort "*** Environment variable APP not found."
|
100
113
|
end
|
101
114
|
unless variable
|
102
|
-
abort "Environment variable DB_ENV_NAME not found."
|
115
|
+
abort "*** Environment variable DB_ENV_NAME not found."
|
103
116
|
end
|
104
117
|
|
105
118
|
database, user, password = remote_credentials(app, variable)
|
@@ -115,9 +128,4 @@ namespace :scalingo do
|
|
115
128
|
yield(database, user, password)
|
116
129
|
close_tunnel.call
|
117
130
|
end
|
118
|
-
|
119
|
-
class VariableError < StandardError
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
131
|
end
|
@@ -45,6 +45,7 @@ namespace :scalingo do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.backup database, user, password, host, port
|
48
|
+
pg_dump_cmd = ENV["PG_DUMP_CMD"] || "pg_dump"
|
48
49
|
user_cmd = ""
|
49
50
|
password_cmd = ""
|
50
51
|
if not user.blank?
|
@@ -54,7 +55,7 @@ namespace :scalingo do
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
exclude_cmd = "-N 'information_schema' -N '^pg_*'"
|
57
|
-
base_cmd = "
|
58
|
+
base_cmd = "#{pg_dump_cmd} --no-owner --no-privileges --clean #{exclude_cmd} --format=c #{user_cmd} -h #{host} -p #{port} -d #{database}"
|
58
59
|
base_cmd << " --if-exists" if pg_restore_after_9_4?
|
59
60
|
output = "rm -rf #{DUMP_PATH} 2>/dev/null && /usr/bin/env PGPASSWORD=[FILTERED] #{base_cmd}"
|
60
61
|
cmd = "rm -rf #{DUMP_PATH} 2>/dev/null && /usr/bin/env #{password_cmd} #{base_cmd}"
|
@@ -69,6 +70,7 @@ namespace :scalingo do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def self.restore database, user, password, host, port
|
73
|
+
pg_restore_cmd = ENV["PG_RESTORE_CMD"] || "pg_restore"
|
72
74
|
if archive_contain_sql(archive_name DUMP_NAME)
|
73
75
|
user_cmd = ""
|
74
76
|
password_cmd = ""
|
@@ -96,7 +98,7 @@ namespace :scalingo do
|
|
96
98
|
end
|
97
99
|
end
|
98
100
|
base_cmd = "tar xvzOf #{archive_name DUMP_NAME} | "
|
99
|
-
pg_cmd = "
|
101
|
+
pg_cmd = "#{pg_restore_cmd} --no-owner --no-privileges --clean"
|
100
102
|
pg_cmd << " --if-exists" if pg_restore_after_9_4?
|
101
103
|
pg_cmd << " #{user_cmd} -h #{host} -p #{port} -d #{database}"
|
102
104
|
output = "#{base_cmd} PGPASSWORD=[FILTERED] #{pg_cmd}"
|
@@ -108,7 +110,8 @@ namespace :scalingo do
|
|
108
110
|
end
|
109
111
|
|
110
112
|
def self.pg_restore_after_9_4?
|
111
|
-
|
113
|
+
pg_restore_cmd = ENV["PG_RESTORE_CMD"] || "pg_restore"
|
114
|
+
version = `#{pg_restore_cmd} --version`.split.last
|
112
115
|
major, minor = version.split('.')
|
113
116
|
major.to_i >= 9 && minor.to_i >= 4
|
114
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scalingo_databases_rake_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scalingo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|