mina-data_sync 1.0.0.beta2 → 1.0.0.beta3
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/.rubocop.yml +1156 -0
- data/README.md +12 -2
- data/lib/mina/data_sync/defaults.rb +1 -2
- data/lib/mina/data_sync/helpers.rb +27 -4
- data/lib/mina/data_sync/tasks.rb +34 -41
- data/lib/mina/data_sync/version.rb +1 -1
- data/lib/mina/data_sync.rb +1 -0
- data/mina-data_sync.gemspec +1 -0
- metadata +17 -2
data/README.md
CHANGED
@@ -38,6 +38,17 @@ mina data_sync:pull # pulls remote to local
|
|
38
38
|
mina data_sync:push # pushes local to remote
|
39
39
|
```
|
40
40
|
|
41
|
+
You can use the only parts of the sync:
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
mina data_sync:dump_remote
|
45
|
+
mina data_sync:dump_local
|
46
|
+
mina data_sync:copy_local_to_remote
|
47
|
+
mina data_sync:copy_remote_to_local
|
48
|
+
mina data_sync:restore_remote
|
49
|
+
mina data_sync:restore_local
|
50
|
+
```
|
51
|
+
|
41
52
|
## Configruation
|
42
53
|
|
43
54
|
configurable variables with defaults
|
@@ -45,8 +56,7 @@ configurable variables with defaults
|
|
45
56
|
set :database_path, "config/database.yml"
|
46
57
|
set :remote_backup_path, 'tmp'
|
47
58
|
set :local_backup_path, -> { ENV['DATA_SYNC_BACKUP_PATH'] || 'tmp' }
|
48
|
-
set :
|
49
|
-
set :dump_data, -> { ENV['dump'] || 'true' } # if false will not dump and copy backup
|
59
|
+
set :backup_file, -> { %{#{fetch(:repository).split('/').last.split('.').first}-#{fetch(:rails_env)}-#{Date.today}.sql} }
|
50
60
|
```
|
51
61
|
|
52
62
|
## Contributing
|
@@ -1,5 +1,4 @@
|
|
1
1
|
set :database_path, 'config/database.yml'
|
2
2
|
set :remote_backup_path, 'tmp'
|
3
3
|
set :local_backup_path, -> { ENV['DATA_SYNC_BACKUP_PATH'] || 'tmp' }
|
4
|
-
set :
|
5
|
-
set :dump_data, -> { ENV['dump'] || 'true' }
|
4
|
+
set :backup_file, -> { ENV['DATA_SYNC_BACKUP_FILE'] || %{#{fetch(:repository).split('/').last.split('.').first}-#{fetch(:rails_env)}-#{Date.today}.sql} }
|
@@ -36,10 +36,33 @@ DATA_SYNC = <<-BASH
|
|
36
36
|
};
|
37
37
|
BASH
|
38
38
|
|
39
|
-
def
|
40
|
-
|
39
|
+
def dump_restore(rails_root, backup_path, mode: :dump, backend: :local)
|
40
|
+
set :rails_env, 'development' if backend == :local
|
41
|
+
comment %{#{mode == :dump ? 'Dumping' : 'Restoring'} database}
|
42
|
+
command %{cd #{rails_root}}
|
43
|
+
command DATA_SYNC.to_s
|
44
|
+
command %{mkdir -p #{backup_path}}
|
45
|
+
command %{CONFIG=$(#{fetch(:rails)} runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json")}
|
46
|
+
comment %{$(data_sync "#{mode}" "#{backup_path}/#{fetch(:backup_file)}" "$CONFIG")}
|
47
|
+
command %{eval $(data_sync "#{mode}" "#{backup_path}/#{fetch(:backup_file)}" "$CONFIG")}
|
41
48
|
end
|
42
49
|
|
43
|
-
def
|
44
|
-
|
50
|
+
def rsync_db(mode: :remote_to_local)
|
51
|
+
if mode == :remote_to_local
|
52
|
+
run :local do
|
53
|
+
comment %{Copying backup}
|
54
|
+
command %{mkdir -p #{fetch(:local_backup_path)}}
|
55
|
+
comment %{Backup: #{fetch(:local_backup_path)}/#{fetch(:backup_file)}}
|
56
|
+
command %{rsync --progress -e "ssh -p #{fetch(:port)}" #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)} #{fetch(:local_backup_path)}/#{fetch(:backup_file)}}
|
57
|
+
end
|
58
|
+
else
|
59
|
+
run :remote do
|
60
|
+
command %{mkdir -p #{fetch(:current_path)}/#{fetch(:remote_backup_path)}}
|
61
|
+
end
|
62
|
+
run :local do
|
63
|
+
comment %{Copying backup}
|
64
|
+
comment %{Backup: #{fetch(:remote_backup_path)}/#{fetch(:backup_file)}}
|
65
|
+
command %{rsync --progress -e "ssh -p #{fetch(:port)}" #{fetch(:local_backup_path)}/#{fetch(:backup_file)} #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}}
|
66
|
+
end
|
67
|
+
end
|
45
68
|
end
|
data/lib/mina/data_sync/tasks.rb
CHANGED
@@ -1,53 +1,46 @@
|
|
1
1
|
namespace :data_sync do
|
2
|
-
task
|
3
|
-
|
2
|
+
task :dump_remote do
|
3
|
+
run :remote do
|
4
|
+
dump_restore(fetch(:current_path), fetch(:remote_backup_path), mode: :dump, backend: :remote)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
task :dump_local do
|
9
|
+
run :local do
|
10
|
+
dump_restore('.', fetch(:local_backup_path), mode: :dump, backend: :local)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task :copy_local_to_remote do
|
15
|
+
rsync_db(mode: :local_to_remote)
|
4
16
|
end
|
5
17
|
|
6
|
-
task
|
18
|
+
task :copy_remote_to_local do
|
19
|
+
rsync_db(mode: :remote_to_local)
|
20
|
+
end
|
21
|
+
|
22
|
+
task :restore_remote do
|
23
|
+
exit unless TTY::Prompt.new.yes?("Are you sure you want to restore #{fetch(:rails_env)} database?")
|
7
24
|
run :remote do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
command "mkdir -p #{fetch(:remote_backup_path)}"
|
12
|
-
command "CONFIG=$(#{fetch(:rails)} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
13
|
-
command %(data_sync "dump" "#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}" "$CONFIG")
|
14
|
-
command %(eval $(data_sync "dump" "#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}" "$CONFIG"))
|
15
|
-
end if fetch(:dump_data) == 'true'
|
25
|
+
dump_restore(fetch(:current_path), fetch(:remote_backup_path), mode: :restore, backend: :remote)
|
26
|
+
end
|
27
|
+
end
|
16
28
|
|
29
|
+
task :restore_local do
|
17
30
|
run :local do
|
18
|
-
|
19
|
-
comment 'Copying backup'
|
20
|
-
command "mkdir -p #{fetch(:local_backup_path)}"
|
21
|
-
command "rsync --progress -e 'ssh -p #{fetch(:port)}' #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)} #{fetch(:local_backup_path)}/#{fetch(:backup_file)}"
|
22
|
-
end
|
23
|
-
if fetch(:restore_data) == 'true'
|
24
|
-
comment 'Restoring database'
|
25
|
-
command "#{DATA_SYNC}"
|
26
|
-
command "CONFIG=$(RAILS_ENV=development #{fetch(:bundle_bin)} exec rails runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
27
|
-
command %(data_sync "restore" "#{fetch(:local_backup_path)}/#{fetch(:backup_file)}" "$CONFIG")
|
28
|
-
command %(eval $(data_sync "restore" "#{fetch(:local_backup_path)}/#{fetch(:backup_file)}" "$CONFIG"))
|
29
|
-
end
|
31
|
+
dump_restore('.', fetch(:local_backup_path), mode: :restore, backend: :local)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
task
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
command %(data_sync "dump" "#{fetch(:local_backup_path)}/#{fetch(:backup_file)}" "$CONFIG")
|
39
|
-
command %(eval $(data_sync "dump" "#{fetch(:local_backup_path)}/#{fetch(:backup_file)}" "$CONFIG"))
|
40
|
-
comment 'Copying backup'
|
41
|
-
command "rsync --progress -e 'ssh -p #{fetch(:port)}' #{fetch(:local_backup_path)}/#{fetch(:backup_file)} #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}"
|
42
|
-
end if fetch(:dump_data) == 'true'
|
35
|
+
task :pull do
|
36
|
+
invoke :'data_sync:dump_remote'
|
37
|
+
invoke :'data_sync:copy_remote_to_local'
|
38
|
+
invoke :'data_sync:restore_local'
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
command "CONFIG=$(#{fetch(:rails)} runner 'puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json')"
|
49
|
-
command %(data_sync "restore" "#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}" "$CONFIG")
|
50
|
-
command %(eval $(data_sync "restore" "#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}" "$CONFIG"))
|
51
|
-
end if fetch(:restore_data) == 'true'
|
41
|
+
task :push do
|
42
|
+
invoke :'data_sync:dump_local'
|
43
|
+
invoke :'data_sync:copy_local_to_remote'
|
44
|
+
invoke :'data_sync:restore_remote'
|
52
45
|
end
|
53
46
|
end
|
data/lib/mina/data_sync.rb
CHANGED
data/mina-data_sync.gemspec
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: 1.0.0.
|
4
|
+
version: 1.0.0.beta3
|
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-08-
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.0.beta2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-prompt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Description
|
70
84
|
email:
|
71
85
|
- d4be4st@gmail.com
|
@@ -74,6 +88,7 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
77
92
|
- Gemfile
|
78
93
|
- LICENSE.txt
|
79
94
|
- README.md
|