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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 131b453d7c94c0f33c3f753b0396581b78c4f2fc
4
- data.tar.gz: fbe879c323fadc4e972236f065c7041647ee9070
3
+ metadata.gz: 0359cc0a28b26e2a1fada7970f2361075efb1ea8
4
+ data.tar.gz: f061f43d322ab4976c7969bdb0c693357f1eb02d
5
5
  SHA512:
6
- metadata.gz: e85e07b2e5f7f6d0fcff1e5c0f861f1888d67011a36e8fe3378ca24864c1f0a2b04f98a8340681e91b70a2467988028414a8a774859d540c047bc09e6fb4335a
7
- data.tar.gz: ff06bd930ffa08c592cafedaf2f9bd08d28c66e4b753caf8a604dbeacc845fe40179c0ea20dfbf989ad504ec227589a39661b6ec127719be968590462a3ffc8b
6
+ metadata.gz: 22648d67d63c41a612b63df742592fcdaabf74889c2d52d3451e197bbf7dfe78497822ee6bfaf2baaba6482dbde5c2b298bf2a1aa655de201ad8314c42b16a4f
7
+ data.tar.gz: 599bda00e0265be9f6c2beadb63e1b620996ef218ea9bd8c20893af93fac9fef956771d83066d8b9f47b233afba38959a66fce90c58d5d80b7cb26d0ba8e43c2
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ *.gem
12
+ tags
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
+
@@ -1,3 +1,3 @@
1
1
  module LoadRemoteDb
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -3,17 +3,18 @@ require 'yaml'
3
3
  require 'json'
4
4
  require 'shellwords'
5
5
 
6
- namespace :load_remote_db do
7
- task :run do |t, _|
8
- args = ARGV
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(args)
13
+ def call
15
14
  env = 'staging'
16
- env = args[1] if args.count > 1
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.sql .)
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.sql")
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.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-13 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler