cap_db_dump 1.3.0 → 1.3.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cap_db_dump/recipes.rb +31 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b17670872f50b5f6e4ced82d27850b86d69f5f544c16ffd2255f9be0550d0f5
4
- data.tar.gz: 95a520425a6edf34da30890fb9cc898fac58b20c9ba5c152b6ca0e7dd7fe89ec
3
+ metadata.gz: 010ed3cf256f446566acc86e8cbf49aa2d4965ea5f0a057dd436c4f41c53dea0
4
+ data.tar.gz: 40adc98e605ef94aee244c90ad859bfc01551dc8f6c62a95a1335455e8851c6b
5
5
  SHA512:
6
- metadata.gz: 4e9a93f1adcbbf42ceeff9f4da05913f2df61ca31be12afa6c42fb44dd0334258f633cc0ce3f7cf91ad5938668b0031ea27df22962f8f9bafc4874983e7208ba
7
- data.tar.gz: a990d7fc1d50cf589c1d0b0af8be81aa238f6c1e75a7f55855d28170213a3f9357aebcd63fbd248a2988fa5ba5afe8e038aa5d2edfcaa362adb2270fec6cddd9
6
+ metadata.gz: 39ac68fc4e29e92b771ed8ccdb2cda3efe517d2b0b99d91db9bbe0b59034bec653334954e93e9098ff4ebd977419596c52b39e63af510dfa37124dc78028e53b
7
+ data.tar.gz: 8b48771c21890446cc650b1e1bd33e82390ec25933ef08c85fba01fff043a20d0b3793e9ef3638631866e137f28734f8ec22b8f7501d483d547543e30fd159e7
@@ -68,8 +68,18 @@ Capistrano::Configuration.instance(:must_exist).load do
68
68
  end
69
69
  end
70
70
 
71
+ def database_password?
72
+ database_password && !database_password.to_s.empty?
73
+ end
74
+
75
+ # --defaults-extra-file must be the first option given to mysqldump
71
76
  def mysql_password_field
72
- database_password && database_password.length > 0 ? "-p#{database_password}" : ""
77
+ database_password? ? "--defaults-extra-file=/dev/stdin" : ""
78
+ end
79
+
80
+ def mysql_password_stdin
81
+ escaped_password = database_password.to_s.gsub("\\") { "\\\\" }
82
+ "[client]\npassword=\"#{escaped_password}\"\n"
73
83
  end
74
84
 
75
85
  def postgres_port
@@ -77,9 +87,20 @@ Capistrano::Configuration.instance(:must_exist).load do
77
87
  end
78
88
 
79
89
  def pg_password
80
- database_password && !database_password.empty? ?
81
- "PGPASSWORD=#{database_password}" :
82
- ""
90
+ database_password? ? "IFS= read -r PGPASSWORD && export PGPASSWORD &&" : ""
91
+ end
92
+
93
+ def pg_password_stdin
94
+ "#{database_password}\n"
95
+ end
96
+
97
+ # A pty would echo the password on stdin back into the (logged) output.
98
+ def run_with_password(command, stdin_data)
99
+ if database_password?
100
+ run command, :data => stdin_data, :eof => true, :pty => false
101
+ else
102
+ run command
103
+ end
83
104
  end
84
105
 
85
106
  def pg_port
@@ -94,9 +115,10 @@ Capistrano::Configuration.instance(:must_exist).load do
94
115
 
95
116
  ignored_tables = ignored_tables.join(" ")
96
117
 
97
- command = "mysqldump -u #{database_username} -h #{database_host} #{mysql_password_field} -Q "
118
+ command = "mysqldump #{mysql_password_field} -u #{database_username} -h #{database_host} -Q "
98
119
  command << "--add-drop-table -O add-locks=FALSE --lock-tables=FALSE --single-transaction "
99
120
  command << "#{ignored_tables} #{database_name} > #{dump_path}"
121
+ password_stdin = mysql_password_stdin
100
122
  elsif database_engine == POSTGRES
101
123
  ignored_tables = schema_only_tables.map { |table_name|
102
124
  "--exclude-table=#{database_name}.#{table_name}"
@@ -109,13 +131,14 @@ Capistrano::Configuration.instance(:must_exist).load do
109
131
  command << "-F#{pg_dump_format} "
110
132
  end
111
133
  command << "#{ignored_tables} #{database_name} > #{dump_path}"
134
+ password_stdin = pg_password_stdin
112
135
  else
113
136
  raise "Unknown database engine. use one of: #{DATABASE_ENGINES.inspect}"
114
137
  end
115
138
 
116
139
  give_description "About to dump production DB"
117
140
 
118
- run command
141
+ run_with_password command, password_stdin
119
142
  dump_schema_tables if schema_only_tables.any?
120
143
  end
121
144
 
@@ -124,7 +147,7 @@ Capistrano::Configuration.instance(:must_exist).load do
124
147
  table_names = schema_only_tables.join(" ")
125
148
 
126
149
  if database_engine == MYSQL
127
- command = "mysqldump -u #{database_username} -h #{database_host} #{mysql_password_field} "
150
+ command = "mysqldump #{mysql_password_field} -u #{database_username} -h #{database_host} "
128
151
  command << "-Q --add-drop-table --single-transaction --no-data #{database_name} #{table_names} >> #{dump_path}"
129
152
  elsif database_engine == POSTGRES
130
153
  raise "not yet supported. PR's welcome! (https://github.com/smtlaissezfaire/cap_db_dump)"
@@ -133,7 +156,7 @@ Capistrano::Configuration.instance(:must_exist).load do
133
156
  end
134
157
 
135
158
  give_description "Dumping schema for tables: #{schema_only_tables.join(", ")}"
136
- run command
159
+ run_with_password command, mysql_password_stdin
137
160
  end
138
161
  end
139
162
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap_db_dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-24 00:00:00.000000000 Z
11
+ date: 2026-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano