load_remote_db 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/load_remote_db/railtie.rb +7 -0
- data/lib/load_remote_db/version.rb +3 -0
- data/lib/load_remote_db.rb +5 -0
- data/lib/tasks/load_remote_db.rake +84 -0
- data/load_remote_db.gemspec +26 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7ac5cba598c037e6b16a22968bfc522a527186b
|
4
|
+
data.tar.gz: a1605f2684f89359606556f8b0acdc5a6f6b4719
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 255c6a4f291c6e496d934a3c7beae988c88c3ab7d0b48ec89bd5b6fbe575e4d31546e6c371c511d761bdb52e139b3b689a1dcf91dd4fea45d6c32a1d9ed006c9
|
7
|
+
data.tar.gz: c8c550d2336d83c0ae1a9095176a9ad6f6be48f90599dba411a2156a250d10f2f91cb280c4d5830e5b51aed650e7b36924396a258b30272e8274074f50c35578
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 James Huynh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# LoadRemoteDb
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/load_remote_db`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'load_remote_db'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install load_remote_db
|
22
|
+
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Simply execute the command:
|
27
|
+
|
28
|
+
$ [bundle exec] rake load_remote_db:run [environment]
|
29
|
+
|
30
|
+
For instance
|
31
|
+
|
32
|
+
$ bundle exec rake load_remote_db:run staging
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
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
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[jameshuynh]/load_remote_db.
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "load_remote_db"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# rubocop:disable all
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
namespace :load_remote_db do
|
7
|
+
task :run do |t, _|
|
8
|
+
args = ARGV
|
9
|
+
RemoteDbLoader.new.call(args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RemoteDbLoader
|
14
|
+
def call(args)
|
15
|
+
env = 'staging'
|
16
|
+
env = args[1] unless args.count > 1
|
17
|
+
|
18
|
+
database_yml =
|
19
|
+
"#{Rails.root}/config/database.yml"
|
20
|
+
development_db = YAML.load_file(database_yml)['development']
|
21
|
+
|
22
|
+
username = development_db['username']
|
23
|
+
password = development_db['password']
|
24
|
+
database = development_db['database']
|
25
|
+
|
26
|
+
eval File.read("#{Rails.root}/config/deploy/#{env}.rb")
|
27
|
+
|
28
|
+
## get remote database config.yml
|
29
|
+
get_db_info_command = %{ssh #{@server_user}@#{@server_ip} \
|
30
|
+
"/home/#{@server_user}/.rbenv/shims/ruby -e \
|
31
|
+
\\"require 'yaml'; \
|
32
|
+
puts YAML.load_file('#{@deploy_to}/shared/config/database.yml')['#{env}']\\""}
|
33
|
+
|
34
|
+
shared_path = "#{@deploy_to}/shared"
|
35
|
+
|
36
|
+
remote_db_config = eval `#{get_db_info_command}`
|
37
|
+
remote_db_username = remote_db_config["username"]
|
38
|
+
remote_db_password = remote_db_config["password"]
|
39
|
+
remote_db_host = remote_db_config["host"]
|
40
|
+
remote_db_name = remote_db_config["database"]
|
41
|
+
|
42
|
+
## run the real backup
|
43
|
+
puts 'Running the remote backup...'
|
44
|
+
mysql_cmd = "mysqldump -u #{remote_db_username} -p'#{remote_db_password}' \
|
45
|
+
-h #{remote_db_host} #{remote_db_name} > #{shared_path}/backup.sql".shellescape
|
46
|
+
backup_command = %(ssh #{@server_user}@#{@server_ip} #{mysql_cmd})
|
47
|
+
system(backup_command)
|
48
|
+
|
49
|
+
puts 'Downloading remote backup file...'
|
50
|
+
download_db_dump_command =
|
51
|
+
%(scp #{@server_user}@#{@server_ip}:#{shared_path}/backup.sql .)
|
52
|
+
|
53
|
+
`#{download_db_dump_command}`
|
54
|
+
|
55
|
+
puts 'Deleting remote backup file...'
|
56
|
+
delete_db_dump_command = %(ssh #{@server_user}@#{@server_ip} \
|
57
|
+
"rm -rf #{shared_path}/backup.sql")
|
58
|
+
|
59
|
+
if password == nil
|
60
|
+
import_db_cmd =
|
61
|
+
%(mysql -u #{username} #{database} < backup.sql)
|
62
|
+
else
|
63
|
+
import_db_cmd =
|
64
|
+
%(mysql -u #{username} -p'#{password}' #{database} < backup.sql)
|
65
|
+
end
|
66
|
+
|
67
|
+
puts 'Importing database into local environment...'
|
68
|
+
`#{import_db_cmd}`
|
69
|
+
|
70
|
+
puts 'Cleaning up...'
|
71
|
+
`rm backup.sql`
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_missing(name, *args, &block)
|
75
|
+
return unless %I[server set].include?(name)
|
76
|
+
@server_ip ||= if name == :server
|
77
|
+
args[0]
|
78
|
+
elsif name == :set && args[0] == :domain
|
79
|
+
args[1]
|
80
|
+
end
|
81
|
+
@server_user ||= args[1] if name == :set && args[0] == :user
|
82
|
+
@deploy_to ||= args[1] if name == :set && args[0] == :deploy_to
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'load_remote_db/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "load_remote_db"
|
8
|
+
spec.version = LoadRemoteDb::VERSION
|
9
|
+
spec.authors = ["James Huynh"]
|
10
|
+
spec.email = ["james@rubify.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Load MySQL Remote DB for Mina/Capistrano}
|
13
|
+
spec.description = %q{Load MySQL Remote DB for Mina/Capistrano}
|
14
|
+
spec.homepage = "https://github.com/jameshuynh/load_remote_db"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: load_remote_db
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Huynh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Load MySQL Remote DB for Mina/Capistrano
|
42
|
+
email:
|
43
|
+
- james@rubify.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/load_remote_db.rb
|
56
|
+
- lib/load_remote_db/railtie.rb
|
57
|
+
- lib/load_remote_db/version.rb
|
58
|
+
- lib/tasks/load_remote_db.rake
|
59
|
+
- load_remote_db.gemspec
|
60
|
+
homepage: https://github.com/jameshuynh/load_remote_db
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Load MySQL Remote DB for Mina/Capistrano
|
84
|
+
test_files: []
|