mina-data_sync 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/config/database.yml +6 -41
- data/lib/mina/data_sync/helpers.rb +40 -23
- data/lib/mina/data_sync/tasks.rb +12 -11
- data/lib/mina/data_sync/version.rb +1 -1
- data/lib/mina/data_sync.rb +0 -8
- metadata +2 -3
- data/lib/mina/tasks/config.rake +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 189a72cf302e49da6dd218a584a40b95dab6b84c
|
4
|
+
data.tar.gz: 45551eeefb495721775d139079ab737e5c6dd600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd31793c16b9ce58c3506b09c6e70968272dd2cfb100b1f649fc0f6e9c7005129adf91f8492efafecee86fabc918e17dd41b6563dcc758cedb11e3c3944c838
|
7
|
+
data.tar.gz: 7b9b272a3016c70d326f4f51317ff6408961e8a86e5c7733b86d1fc1ffcace5b2731b185ee7a466b9a8b2dfd2e237a0421f947d9dbcb2ddb3809f9f5fde90f3e
|
data/config/database.yml
CHANGED
@@ -1,46 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Install the MYSQL driver
|
4
|
-
# gem install mysql2
|
5
|
-
#
|
6
|
-
# Ensure the MySQL gem is defined in your Gemfile
|
7
|
-
# gem 'mysql2'
|
8
|
-
#
|
9
|
-
# And be sure to use new-style password hashing:
|
10
|
-
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
11
|
-
development:
|
12
|
-
adapter: mysql2
|
13
|
-
encoding: utf8
|
14
|
-
database: test
|
15
|
-
pool: 5
|
16
|
-
username: root
|
17
|
-
password:
|
18
|
-
|
19
|
-
# Warning: The database defined as "test" will be erased and
|
20
|
-
# re-generated from your development database when you run "rake".
|
21
|
-
# Do not set this db to the same as development or production.
|
22
|
-
test:
|
23
|
-
adapter: mysql2
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
24
3
|
encoding: utf8
|
25
|
-
database: psylog_test
|
26
4
|
pool: 5
|
27
|
-
username:
|
5
|
+
username: postgres
|
28
6
|
password:
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
encoding: utf8
|
34
|
-
database: psylog_infinum_co
|
35
|
-
pool: 5
|
36
|
-
username: psylog_p
|
37
|
-
password: DzmKmmMw
|
8
|
+
development:
|
9
|
+
<<: *default
|
10
|
+
database: truck_development_2
|
38
11
|
|
39
|
-
staging:
|
40
|
-
host: localhost
|
41
|
-
adapter: mysql2
|
42
|
-
encoding: utf8
|
43
|
-
database: psylog_staging_infinum_co
|
44
|
-
pool: 5
|
45
|
-
username: psylog_s
|
46
|
-
password: uRfbBD1S
|
@@ -1,28 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
when
|
1
|
+
COMMAND = <<-RUBY
|
2
|
+
method = ARGV[0]
|
3
|
+
dc = JSON.parse(ARGV[2])
|
4
|
+
adapter = dc["adapter"]
|
5
|
+
database = dc["database"]
|
6
|
+
host = dc["host"]
|
7
|
+
username = dc["username"]
|
8
|
+
password = dc["password"]
|
9
|
+
port = dc["port"]
|
10
|
+
arguments = ""
|
11
|
+
case adapter.to_s
|
12
|
+
when "postgresql"
|
13
|
+
arguments += "PGPASSWORD=" + password if password
|
14
|
+
arguments += method == "dump" ? "pg_dump" : "psql -q"
|
15
|
+
arguments += " -d " + database if database
|
16
|
+
arguments += " -h " + host if host
|
17
|
+
arguments += " -U " + username if username
|
18
|
+
arguments += " -p " + port.to_s if port
|
19
|
+
arguments += " -O -c"
|
20
|
+
when "mysql2"
|
21
|
+
arguments += method == "dump" ? "mysqldump" : "mysql"
|
22
|
+
arguments += " " + database if database
|
23
|
+
arguments += " -h " + host if host
|
24
|
+
arguments += " -u " + username if username
|
25
|
+
arguments += " --password=" + password if password
|
26
|
+
arguments += " -P " + port.to_s if port
|
13
27
|
end
|
14
|
-
|
28
|
+
arguments += method == "dump" ? " > " : " < "
|
29
|
+
arguments += ARGV[1]
|
30
|
+
puts arguments
|
31
|
+
RUBY
|
15
32
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
33
|
+
DATA_SYNC = <<-BASH
|
34
|
+
function data_sync {
|
35
|
+
ruby -rjson -e '#{COMMAND}' "$@"
|
36
|
+
};
|
37
|
+
BASH
|
38
|
+
|
39
|
+
def config
|
40
|
+
"#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json'"
|
21
41
|
end
|
22
42
|
|
23
|
-
def
|
24
|
-
|
25
|
-
when 'postgresql' then '-O -c'
|
26
|
-
when 'mysql2' then ''
|
27
|
-
end
|
43
|
+
def backup_file
|
44
|
+
"#{repository.split('/').last.split('.').first}-#{rails_env}-#{Date.today}.sql"
|
28
45
|
end
|
data/lib/mina/data_sync/tasks.rb
CHANGED
@@ -8,20 +8,20 @@ namespace :data_sync do
|
|
8
8
|
|
9
9
|
queue "echo '-----> Dumping database'"
|
10
10
|
queue "cd #{deploy_to}/#{current_path}"
|
11
|
-
queue "
|
11
|
+
queue "#{DATA_SYNC}"
|
12
12
|
queue "mkdir -p #{remote_backup_path}"
|
13
|
-
queue
|
14
|
-
queue!
|
13
|
+
queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
14
|
+
queue! %(eval $(data_sync "dump" "#{remote_backup_path}/#{backup_file}" "$CONFIG"))
|
15
15
|
|
16
16
|
to :after_hook do
|
17
17
|
queue "echo '-----> Copying backup'"
|
18
18
|
queue "mkdir -p #{local_backup_path}"
|
19
|
+
queue "#{DATA_SYNC}"
|
19
20
|
queue! "rsync --progress -e 'ssh -p #{port}' #{user}@#{domain}:#{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file} #{local_backup_path}/#{backup_file}"
|
20
|
-
queue "echo '-----> Restoring database'"
|
21
21
|
if restore_data == 'true'
|
22
|
-
queue "
|
23
|
-
queue
|
24
|
-
queue
|
22
|
+
queue "echo '-----> Restoring database'"
|
23
|
+
queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
24
|
+
queue %(eval $(data_sync "restore" "#{local_backup_path}/#{backup_file}" "$CONFIG"))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -31,8 +31,9 @@ namespace :data_sync do
|
|
31
31
|
|
32
32
|
to :before_hook do
|
33
33
|
queue "echo '-----> Dumping database'"
|
34
|
-
queue "
|
35
|
-
queue
|
34
|
+
queue "#{DATA_SYNC}"
|
35
|
+
queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
36
|
+
queue! %(eval $(data_sync "dump" "#{local_backup_path}/#{backup_file}" "$CONFIG"))
|
36
37
|
queue "echo '-----> Copying backup'"
|
37
38
|
queue! "rsync --progress -e 'ssh -p #{port}' #{local_backup_path}/#{backup_file} #{user}@#{domain}:#{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file}"
|
38
39
|
end
|
@@ -40,8 +41,8 @@ namespace :data_sync do
|
|
40
41
|
if restore_data == 'true'
|
41
42
|
queue "echo '-----> Restoring database'"
|
42
43
|
queue "cd #{deploy_to}/#{current_path}"
|
43
|
-
queue "
|
44
|
-
queue
|
44
|
+
queue "CONFIG=$(#{rails} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
45
|
+
queue %(eval $(data_sync "restore" "#{remote_backup_path}/#{backup_file}" "$CONFIG"))
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/lib/mina/data_sync.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-data_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stjepan Hadjic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- lib/mina/data_sync/helpers.rb
|
86
86
|
- lib/mina/data_sync/tasks.rb
|
87
87
|
- lib/mina/data_sync/version.rb
|
88
|
-
- lib/mina/tasks/config.rake
|
89
88
|
- mina-data_sync.gemspec
|
90
89
|
homepage: https://github.com/d4be4st/mina-data_sync
|
91
90
|
licenses:
|
data/lib/mina/tasks/config.rake
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
namespace :mina_data_sync do
|
2
|
-
task config: :environment do
|
3
|
-
dc = ActiveRecord::Base.configurations[Rails.env].to_yaml
|
4
|
-
adapter = dc['adapter']
|
5
|
-
database = dc['database']
|
6
|
-
host = dc['host']
|
7
|
-
username = dc['username']
|
8
|
-
password = dc['password']
|
9
|
-
port = dc['port']
|
10
|
-
arguments = ''
|
11
|
-
case adapter.to_s
|
12
|
-
when 'postgresql'
|
13
|
-
arguments += ' -d ' + database if database
|
14
|
-
arguments += ' -h ' + host if host
|
15
|
-
arguments += ' -U ' + username if username
|
16
|
-
arguments += ' -p ' + port.to_s if port
|
17
|
-
when 'mysql2'
|
18
|
-
arguments += ' ' + database if database
|
19
|
-
arguments += ' -h ' + host if host
|
20
|
-
arguments += ' -u ' + username if username
|
21
|
-
arguments += ' --password=' + password if password
|
22
|
-
arguments += ' -P ' + port.to_s if port
|
23
|
-
end
|
24
|
-
puts arguments
|
25
|
-
end
|
26
|
-
end
|