swarm_cluster_cli_ope 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba2cb5ef2e4841d95dedbfcd147a2b48048ba625c6b85f5559c1fd6d59bf530
|
4
|
+
data.tar.gz: edcdb54c2423b0aef73bba9d098d0738eb89d907aae65203b8ec473e2a40464e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71eb5c600a1615c5c292f439ca8afb6ca6ff43ef93fdf6d1b249617028351c9569a1c7c1cc7b56b75eb57fa6008a4b7682ed0b6d850e42929ce3c41678dba968
|
7
|
+
data.tar.gz: 23d553a4b9c64b0a39b5efd7358751bed3ff7944884b767efce7419ccdc23b1423cf369111795d501ee76fa1b6cbd2940963186753e2405b9d14c1b7367d4de0
|
data/Gemfile.lock
CHANGED
@@ -28,11 +28,13 @@ module SwarmClusterCliOpe
|
|
28
28
|
database_name: #{local.database_name}
|
29
29
|
username: #{local.username}
|
30
30
|
password: #{local.password}
|
31
|
+
version: #{local.database_version}
|
31
32
|
remote:
|
32
33
|
service_name: #{remote.service_name}
|
33
34
|
database_name: #{remote.database_name}
|
34
35
|
username: #{remote.username}
|
35
|
-
password: #{remote.password}
|
36
|
+
password: #{remote.password}
|
37
|
+
version: #{remote.database_version}"
|
36
38
|
|
37
39
|
end
|
38
40
|
|
@@ -34,6 +34,8 @@ module SwarmClusterCliOpe
|
|
34
34
|
define_cfgs :username, default_env: "MYSQL_USER", configuration_name: :mysql_user, default_value: 'root'
|
35
35
|
define_cfgs :password, default_env: "MYSQL_PASSWORD", configuration_name: :mysql_password, default_value: 'root'
|
36
36
|
|
37
|
+
define_cfgs :database_version, default_env: "MYSQL_MAJOR", configuration_name: :mysql_version
|
38
|
+
|
37
39
|
end
|
38
40
|
|
39
41
|
|
@@ -2,28 +2,27 @@ module SwarmClusterCliOpe
|
|
2
2
|
module SyncConfigs
|
3
3
|
class PostGres < BaseDatabase
|
4
4
|
|
5
|
-
|
5
|
+
|
6
6
|
def pull
|
7
7
|
resume('pull')
|
8
8
|
|
9
|
-
dump_cmd = dump_cmd(remote.username, remote.password, remote.database_name)
|
10
|
-
logger.info{ "DUMP COMMAND: #{dump_cmd.join(' ')}"}
|
11
9
|
if yes?("Confermare il comando?[y,yes]")
|
10
|
+
|
12
11
|
tmp_file = "/tmp/#{Time.now.to_i}.sql.gz"
|
13
|
-
|
14
|
-
|
12
|
+
dump_cmd(remote, tmp_file)
|
13
|
+
local.container.copy_in(tmp_file, tmp_file)
|
15
14
|
|
16
15
|
# drop old db and recreate
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
if Gem::Version.new(local.database_version) <= Gem::Version.new("12")
|
17
|
+
close_connections_and_drop_cmd(local)
|
18
|
+
else
|
19
|
+
raise "DA ANALIZZARE QUANDO LA 13 disponibile....dropdb ha un force come parametro"
|
20
|
+
end
|
21
|
+
|
22
|
+
create_cmd(local)
|
23
|
+
|
24
|
+
restore_cmd(local, tmp_file)
|
25
|
+
|
27
26
|
end
|
28
27
|
true
|
29
28
|
end
|
@@ -32,25 +31,22 @@ module SwarmClusterCliOpe
|
|
32
31
|
def push
|
33
32
|
resume('PUSH')
|
34
33
|
|
35
|
-
dump_cmd = dump_cmd(local.username, local.password, local.database_name)
|
36
|
-
say "DUMP COMMAND: #{dump_cmd.join(' ')}"
|
37
34
|
if yes?("ATTENZIONE !!!!!!PUSH!!!!! - Confermare il comando?[y,yes]")
|
35
|
+
|
38
36
|
tmp_file = "/tmp/#{Time.now.to_i}.sql.gz"
|
39
|
-
|
40
|
-
container.copy_in(tmp_file, tmp_file)
|
37
|
+
dump_cmd(local, tmp_file)
|
38
|
+
remote.container.copy_in(tmp_file, tmp_file)
|
41
39
|
|
42
40
|
# drop old db and recreate
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
if Gem::Version.new(local.database_version) <= Gem::Version.new("12")
|
42
|
+
close_connections_and_drop_cmd(remote)
|
43
|
+
else
|
44
|
+
raise "DA ANALIZZARE QUANDO LA 13 disponibile....dropdb ha un force come parametro"
|
45
|
+
end
|
46
|
+
create_cmd(remote)
|
46
47
|
|
47
|
-
|
48
|
-
logger.info{ "CREATE COMMAND: #{create_cmd.join(' ')}"}
|
49
|
-
container.exec("bash -c '#{create_cmd.join(' ')}'")
|
48
|
+
restore_cmd(remote, tmp_file)
|
50
49
|
|
51
|
-
restore_cmd = restore_cmd(remote.username, remote.password, remote.database_name, tmp_file)
|
52
|
-
say "RESTORE COMMAND: #{restore_cmd.join(' ')}"
|
53
|
-
container.exec("bash -c '#{restore_cmd.join(' ')}'")
|
54
50
|
end
|
55
51
|
true
|
56
52
|
end
|
@@ -63,53 +59,101 @@ module SwarmClusterCliOpe
|
|
63
59
|
define_cfgs :username, default_env: "POSTGRES_USER", configuration_name: :pg_user, default_value: 'postgres'
|
64
60
|
define_cfgs :password, default_env: "POSTGRES_PASSWORD", configuration_name: :pg_password
|
65
61
|
|
62
|
+
define_cfgs :database_version, default_env: "PG_MAJOR", configuration_name: :pg_version
|
63
|
+
|
66
64
|
end
|
67
65
|
|
68
66
|
private
|
69
67
|
|
70
|
-
|
68
|
+
# @param [EnvConfigs] config
|
69
|
+
def create_cmd(config)
|
71
70
|
create_cmd = []
|
72
|
-
create_cmd << "PGPASSWORD=\"#{password}\""
|
71
|
+
create_cmd << "PGPASSWORD=\"#{config.password}\""
|
73
72
|
create_cmd << 'createdb'
|
74
|
-
create_cmd << "--username=#{username}"
|
75
|
-
create_cmd << database_name
|
76
|
-
end
|
73
|
+
create_cmd << "--username=#{config.username}"
|
74
|
+
create_cmd << config.database_name
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
drop_cmd << "PGPASSWORD=\"#{password}\""
|
81
|
-
drop_cmd << 'dropdb'
|
82
|
-
drop_cmd << "--username=#{username}"
|
83
|
-
drop_cmd << database_name
|
84
|
-
drop_cmd
|
76
|
+
logger.info { "CREATE COMMAND: #{create_cmd.join(' ')}" }
|
77
|
+
config.container.exec("bash -c '#{create_cmd.join(' ')} || true'")
|
85
78
|
end
|
86
79
|
|
87
|
-
|
80
|
+
# @param [EnvConfigs] config
|
81
|
+
# def drop_cmd(config)
|
82
|
+
# drop_cmd = []
|
83
|
+
# drop_cmd << "PGPASSWORD=\"#{config.password}\""
|
84
|
+
# drop_cmd << 'dropdb'
|
85
|
+
# drop_cmd << '--if-exists'
|
86
|
+
# drop_cmd << "--username=#{config.username}"
|
87
|
+
# drop_cmd << config.database_name
|
88
|
+
# drop_cmd
|
89
|
+
#
|
90
|
+
# logger.info { "DROP COMMAND: #{drop_cmd.join(' ')}" }
|
91
|
+
# config.container.exec("bash -c '#{drop_cmd.join(' ')}'")
|
92
|
+
# end
|
93
|
+
|
94
|
+
# @param [EnvConfigs] config
|
95
|
+
def restore_cmd(config, tmp_file)
|
88
96
|
restore_cmd = []
|
89
|
-
restore_cmd << "PGPASSWORD=\"#{password}\""
|
97
|
+
restore_cmd << "PGPASSWORD=\"#{config.password}\""
|
90
98
|
restore_cmd << 'pg_restore'
|
91
99
|
restore_cmd << '--no-acl'
|
92
100
|
restore_cmd << '--no-owner'
|
93
|
-
restore_cmd << "--username=#{username}"
|
94
|
-
restore_cmd << "--dbname=#{database_name}"
|
101
|
+
restore_cmd << "--username=#{config.username}"
|
102
|
+
restore_cmd << "--dbname=#{config.database_name}"
|
95
103
|
restore_cmd << tmp_file
|
96
104
|
restore_cmd
|
105
|
+
|
106
|
+
logger.info { "RESTORE COMMAND: #{restore_cmd.join(' ')}" }
|
107
|
+
config.container.exec("bash -c '#{restore_cmd.join(' ')}'")
|
97
108
|
end
|
98
109
|
|
99
|
-
|
110
|
+
# @param [EnvConfigs] config
|
111
|
+
def dump_cmd(config, file)
|
100
112
|
dump_cmd = []
|
101
|
-
dump_cmd << "PGPASSWORD=\"#{password}\""
|
113
|
+
dump_cmd << "PGPASSWORD=\"#{config.password}\""
|
102
114
|
dump_cmd << 'pg_dump'
|
103
115
|
dump_cmd << '--no-acl'
|
104
116
|
dump_cmd << '--no-owner'
|
105
|
-
dump_cmd << "--username=#{username}"
|
117
|
+
dump_cmd << "--username=#{config.username}"
|
106
118
|
dump_cmd << '--format=custom'
|
107
119
|
dump_cmd << '--compress=9'
|
108
|
-
dump_cmd << database_name
|
120
|
+
dump_cmd << config.database_name
|
109
121
|
dump_cmd
|
122
|
+
|
123
|
+
logger.info { "DUMP COMMAND: #{dump_cmd.join(' ')}" }
|
124
|
+
config.container.exec("bash -c '#{dump_cmd.join(' ')}' > #{file}")
|
125
|
+
|
110
126
|
end
|
111
127
|
|
112
128
|
|
129
|
+
# @param [EnvConfigs] config
|
130
|
+
def close_connections_and_drop_cmd(config)
|
131
|
+
cmd = []
|
132
|
+
cmd << "PGPASSWORD=\"#{config.password}\""
|
133
|
+
|
134
|
+
sql = []
|
135
|
+
sql << "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '\"'\"'#{config.database_name}'\"'\"' AND pid <> pg_backend_pid();;"
|
136
|
+
sql << "DROP DATABASE IF EXISTS #{config.database_name};"
|
137
|
+
|
138
|
+
cmd << "echo \"#{sql.join(" ")}\" "
|
139
|
+
cmd << '|'
|
140
|
+
cmd << 'psql'
|
141
|
+
cmd << "-U #{config.username}"
|
142
|
+
cmd << "postgres"
|
143
|
+
cmd
|
144
|
+
|
145
|
+
logger.info { "CLOSE CONNECTIONS COMMAND: #{cmd.join(' ')}" }
|
146
|
+
config.container.exec("bash -c '#{cmd.join(' ')}'")
|
147
|
+
end
|
148
|
+
|
149
|
+
# quello che fa capistrano quando copia in locale - utenze inventate
|
150
|
+
# gzip -d cortobio_production_new_2020-09-10-171742.sql.gz &&
|
151
|
+
# PGPASSWORD='root' psql -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'development' AND pid <> pg_backend_pid();;" -U root -h 0.0.0.0 -p 32790 development;
|
152
|
+
# PGPASSWORD='root' dropdb -U root -h 0.0.0.0 -p 32790 development;
|
153
|
+
# PGPASSWORD='root' createdb -U root -h 0.0.0.0 -p 32790 development;
|
154
|
+
# PGPASSWORD='root' psql -U root -h 0.0.0.0 -p 32790 -d development < ./cortobio_production_new_2020-09-10-171742.sql
|
155
|
+
|
156
|
+
|
113
157
|
end
|
114
158
|
end
|
115
159
|
end
|