load_remote_db 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +7 -2
- data/lib/load_remote_db/version.rb +1 -1
- data/lib/tasks/load_remote_db.rake +42 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0359cc0a28b26e2a1fada7970f2361075efb1ea8
|
4
|
+
data.tar.gz: f061f43d322ab4976c7969bdb0c693357f1eb02d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22648d67d63c41a612b63df742592fcdaabf74889c2d52d3451e197bbf7dfe78497822ee6bfaf2baaba6482dbde5c2b298bf2a1aa655de201ad8314c42b16a4f
|
7
|
+
data.tar.gz: 599bda00e0265be9f6c2beadb63e1b620996ef218ea9bd8c20893af93fac9fef956771d83066d8b9f47b233afba38959a66fce90c58d5d80b7cb26d0ba8e43c2
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -21,15 +21,18 @@ Or install it yourself as:
|
|
21
21
|
$ gem install load_remote_db
|
22
22
|
|
23
23
|
|
24
|
+
|
24
25
|
## Usage
|
25
26
|
|
26
27
|
Simply execute the command:
|
27
28
|
|
28
|
-
$ [bundle exec] rake load_remote_db:run [environment]
|
29
|
+
$ [bundle exec] rake load_remote_db:run [SERVER=environment] [SYNC_FOLDER=folder]
|
29
30
|
|
30
31
|
For instance
|
31
32
|
|
32
|
-
$ bundle exec rake load_remote_db:run staging
|
33
|
+
$ bundle exec rake load_remote_db:run SERVER=staging
|
34
|
+
$ bundle exec rake load_remote_db:run SERVER=staging SYNC_FOLDER=public/system
|
35
|
+
|
33
36
|
|
34
37
|
## Development
|
35
38
|
|
@@ -38,6 +41,7 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
38
41
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
42
|
|
40
43
|
|
44
|
+
|
41
45
|
## Contributing
|
42
46
|
|
43
47
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[jameshuynh]/load_remote_db.
|
@@ -49,3 +53,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[james
|
|
49
53
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
50
54
|
|
51
55
|
|
56
|
+
|
@@ -3,17 +3,18 @@ require 'yaml'
|
|
3
3
|
require 'json'
|
4
4
|
require 'shellwords'
|
5
5
|
|
6
|
-
namespace :
|
7
|
-
task :
|
8
|
-
|
9
|
-
RemoteDbLoader.new.call(args)
|
6
|
+
namespace :db do
|
7
|
+
task :load_from_remote do |t, _|
|
8
|
+
RemoteDbLoader.new.call
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
class RemoteDbLoader
|
14
|
-
def call
|
13
|
+
def call
|
15
14
|
env = 'staging'
|
16
|
-
env =
|
15
|
+
env = ENV['SERVER'] if ENV['SERVER'].present?
|
16
|
+
|
17
|
+
to_be_rsync_folder = ENV['SYNC_FOLDER']
|
17
18
|
|
18
19
|
database_yml =
|
19
20
|
"#{Rails.root}/config/database.yml"
|
@@ -46,15 +47,35 @@ class RemoteDbLoader
|
|
46
47
|
backup_command = %(ssh #{@server_user}@#{@server_ip} #{mysql_cmd})
|
47
48
|
system(backup_command)
|
48
49
|
|
50
|
+
check_gzip_exist_cmd = 'which gzip'
|
51
|
+
check_gzip_exist_remote_cmd =
|
52
|
+
%(ssh #{@server_user}@#{@server_ip} #{check_gzip_exist_cmd})
|
53
|
+
|
54
|
+
puts 'Checking for remote gzip location...'
|
55
|
+
gzip_exist = system(check_gzip_exist_remote_cmd) != ''
|
56
|
+
|
57
|
+
if gzip_exist
|
58
|
+
puts 'zipping remote backup file...'
|
59
|
+
zip_cmd = "gzip -f #{shared_path}/backup.sql"
|
60
|
+
zip_cmd_remote =
|
61
|
+
%(ssh #{@server_user}@#{@server_ip} #{zip_cmd})
|
62
|
+
system(zip_cmd_remote)
|
63
|
+
end
|
64
|
+
|
49
65
|
puts 'Downloading remote backup file...'
|
66
|
+
bk_extension = gzip_exist ? 'sql.gz' : 'sql'
|
50
67
|
download_db_dump_command =
|
51
|
-
%(scp #{@server_user}@#{@server_ip}:#{shared_path}/backup
|
68
|
+
%(scp #{@server_user}@#{@server_ip}:#{shared_path}/backup.#{bk_extension} .)
|
52
69
|
|
53
70
|
`#{download_db_dump_command}`
|
54
71
|
|
55
72
|
puts 'Deleting remote backup file...'
|
56
73
|
delete_db_dump_command = %(ssh #{@server_user}@#{@server_ip} \
|
57
|
-
"rm -rf #{shared_path}/backup
|
74
|
+
"rm -rf #{shared_path}/backup.#{bk_extension}")
|
75
|
+
|
76
|
+
if gzip_exist
|
77
|
+
`gunzip backup.sql.gz`
|
78
|
+
end
|
58
79
|
|
59
80
|
if password == nil
|
60
81
|
import_db_cmd =
|
@@ -67,8 +88,20 @@ class RemoteDbLoader
|
|
67
88
|
puts 'Importing database into local environment...'
|
68
89
|
`#{import_db_cmd}`
|
69
90
|
|
70
|
-
puts 'Cleaning up...'
|
91
|
+
puts 'Cleaning up database backup...'
|
71
92
|
`rm backup.sql`
|
93
|
+
|
94
|
+
if to_be_rsync_folder
|
95
|
+
puts "Synchorinizing #{to_be_rsync_folder} folder..."
|
96
|
+
`mkdir -p 'public/#{to_be_rsync_folder.gsub('public/', '')}'`
|
97
|
+
sync_folder_cmd = %(rsync -r \
|
98
|
+
#{@server_user}@#{@server_ip}:#{shared_path}/#{to_be_rsync_folder} \
|
99
|
+
'public/#{to_be_rsync_folder.gsub('public/', '')}')
|
100
|
+
puts sync_folder_cmd
|
101
|
+
system(sync_folder_cmd)
|
102
|
+
end
|
103
|
+
|
104
|
+
puts 'DONE!'
|
72
105
|
end
|
73
106
|
|
74
107
|
def method_missing(name, *args, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: load_remote_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Huynh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|