cap_db_dump 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cap_db_dump/recipes.rb +72 -14
- metadata +39 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9b17670872f50b5f6e4ced82d27850b86d69f5f544c16ffd2255f9be0550d0f5
|
4
|
+
data.tar.gz: 95a520425a6edf34da30890fb9cc898fac58b20c9ba5c152b6ca0e7dd7fe89ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e9a93f1adcbbf42ceeff9f4da05913f2df61ca31be12afa6c42fb44dd0334258f633cc0ce3f7cf91ad5938668b0031ea27df22962f8f9bafc4874983e7208ba
|
7
|
+
data.tar.gz: a990d7fc1d50cf589c1d0b0af8be81aa238f6c1e75a7f55855d28170213a3f9357aebcd63fbd248a2988fa5ba5afe8e038aa5d2edfcaa362adb2270fec6cddd9
|
data/lib/cap_db_dump/recipes.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
2
2
|
namespace :database do
|
3
|
+
DATABASE_ENGINES = [
|
4
|
+
MYSQL = :mysql,
|
5
|
+
POSTGRES = :psql,
|
6
|
+
]
|
7
|
+
|
3
8
|
# a list of tables for which only the schema, but no data should be dumped.
|
4
9
|
set :schema_only_tables, []
|
5
10
|
set :dump_root_path, "/tmp"
|
6
11
|
set :formatted_time, Time.now.utc.strftime("%Y-%m-%d-%H:%M:%S")
|
12
|
+
set :database_engine, :mysql # specify :mysql | :psql
|
13
|
+
# https://www.postgresql.org/docs/12/app-pgdump.html
|
14
|
+
set :pg_dump_format, :c # specify c: 'compressed' (aka -Fc), :d 'directory', or set to nil for plain text
|
7
15
|
|
8
16
|
module CapDbDumpHelpers
|
9
17
|
def dump_path
|
@@ -30,6 +38,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
30
38
|
database_yml_in_env["password"]
|
31
39
|
end
|
32
40
|
|
41
|
+
def database_port
|
42
|
+
database_yml_in_env["port"]
|
43
|
+
end
|
44
|
+
|
33
45
|
def database_yml_in_env
|
34
46
|
database_yml[rails_env]
|
35
47
|
end
|
@@ -47,25 +59,59 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
47
59
|
|
48
60
|
task :read_db_yml, tasks_matching_for_db_dump do
|
49
61
|
@database_yml ||= begin
|
50
|
-
|
51
|
-
|
62
|
+
if dry_run
|
63
|
+
raise "Cannot be run in dry_run mode!"
|
64
|
+
end
|
65
|
+
|
66
|
+
yaml = capture("cat #{current_path}/config/database.yml")
|
67
|
+
YAML.safe_load(yaml, aliases: true)
|
52
68
|
end
|
53
69
|
end
|
54
70
|
|
55
|
-
def
|
71
|
+
def mysql_password_field
|
56
72
|
database_password && database_password.length > 0 ? "-p#{database_password}" : ""
|
57
73
|
end
|
58
74
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
}
|
75
|
+
def postgres_port
|
76
|
+
database_port ? "-p #{database_port}" : ""
|
77
|
+
end
|
63
78
|
|
64
|
-
|
79
|
+
def pg_password
|
80
|
+
database_password && !database_password.empty? ?
|
81
|
+
"PGPASSWORD=#{database_password}" :
|
82
|
+
""
|
83
|
+
end
|
84
|
+
|
85
|
+
def pg_port
|
86
|
+
database_port && !database_port.empty? ? "-p #{database_port}" : ""
|
87
|
+
end
|
65
88
|
|
66
|
-
|
67
|
-
|
68
|
-
|
89
|
+
task :create_dump, tasks_matching_for_db_dump do
|
90
|
+
if database_engine == MYSQL
|
91
|
+
ignored_tables = schema_only_tables.map { |table_name|
|
92
|
+
"--ignore-table=#{database_name}.#{table_name}"
|
93
|
+
}
|
94
|
+
|
95
|
+
ignored_tables = ignored_tables.join(" ")
|
96
|
+
|
97
|
+
command = "mysqldump -u #{database_username} -h #{database_host} #{mysql_password_field} -Q "
|
98
|
+
command << "--add-drop-table -O add-locks=FALSE --lock-tables=FALSE --single-transaction "
|
99
|
+
command << "#{ignored_tables} #{database_name} > #{dump_path}"
|
100
|
+
elsif database_engine == POSTGRES
|
101
|
+
ignored_tables = schema_only_tables.map { |table_name|
|
102
|
+
"--exclude-table=#{database_name}.#{table_name}"
|
103
|
+
}
|
104
|
+
|
105
|
+
ignored_tables = ignored_tables.join(" ")
|
106
|
+
|
107
|
+
command = "#{pg_password} pg_dump -U #{database_username} -h #{database_host} #{postgres_port} "
|
108
|
+
if pg_dump_format
|
109
|
+
command << "-F#{pg_dump_format} "
|
110
|
+
end
|
111
|
+
command << "#{ignored_tables} #{database_name} > #{dump_path}"
|
112
|
+
else
|
113
|
+
raise "Unknown database engine. use one of: #{DATABASE_ENGINES.inspect}"
|
114
|
+
end
|
69
115
|
|
70
116
|
give_description "About to dump production DB"
|
71
117
|
|
@@ -77,8 +123,14 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
77
123
|
if schema_only_tables.any?
|
78
124
|
table_names = schema_only_tables.join(" ")
|
79
125
|
|
80
|
-
|
81
|
-
|
126
|
+
if database_engine == MYSQL
|
127
|
+
command = "mysqldump -u #{database_username} -h #{database_host} #{mysql_password_field} "
|
128
|
+
command << "-Q --add-drop-table --single-transaction --no-data #{database_name} #{table_names} >> #{dump_path}"
|
129
|
+
elsif database_engine == POSTGRES
|
130
|
+
raise "not yet supported. PR's welcome! (https://github.com/smtlaissezfaire/cap_db_dump)"
|
131
|
+
else
|
132
|
+
raise "Unknown database engine. use one of: #{DATABASE_ENGINES.inspect}"
|
133
|
+
end
|
82
134
|
|
83
135
|
give_description "Dumping schema for tables: #{schema_only_tables.join(", ")}"
|
84
136
|
run command
|
@@ -102,8 +154,14 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
102
154
|
end
|
103
155
|
|
104
156
|
task :transfer, tasks_matching_for_db_dump do
|
157
|
+
# TODO: should look in /tmp for latest file
|
105
158
|
give_description "Grabbing the dump"
|
106
|
-
|
159
|
+
gzip_file = "#{dump_path}.gz"
|
160
|
+
download(gzip_file, ".", :via => :scp)
|
161
|
+
|
162
|
+
give_description "Symlinking locally"
|
163
|
+
base_name = File.basename(gzip_file)
|
164
|
+
`ln -sf #{base_name} current.sql.gz`
|
107
165
|
end
|
108
166
|
end
|
109
167
|
end
|
metadata
CHANGED
@@ -1,16 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cap_db_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Scott Taylor
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.15.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.15.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-ssh
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.2.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.2.3
|
14
41
|
description: Capistrano tasks for dumping your mysql database + transfering to your
|
15
42
|
local machine
|
16
43
|
email: scott@railsnewbie.com
|
@@ -21,26 +48,24 @@ files:
|
|
21
48
|
- lib/cap_db_dump/recipes.rb
|
22
49
|
homepage: https://github.com/smtlaissezfaire/cap_db_dump
|
23
50
|
licenses: []
|
24
|
-
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
25
53
|
rdoc_options: []
|
26
54
|
require_paths:
|
27
55
|
- lib
|
28
56
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
57
|
requirements:
|
31
|
-
- -
|
58
|
+
- - ">="
|
32
59
|
- !ruby/object:Gem::Version
|
33
60
|
version: '0'
|
34
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
62
|
requirements:
|
37
|
-
- -
|
63
|
+
- - ">="
|
38
64
|
- !ruby/object:Gem::Version
|
39
65
|
version: '0'
|
40
66
|
requirements: []
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
specification_version: 3
|
67
|
+
rubygems_version: 3.5.9
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
45
70
|
summary: cap_db_dump
|
46
71
|
test_files: []
|