morse_mysql_dump 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7111df57ccb29dec40867bac251317052655fe9
4
+ data.tar.gz: 8c445aaf9b5baa0f14bf9ac601154afced45d208
5
+ SHA512:
6
+ metadata.gz: eafb9dbdabde4e922daa69b77cc4a68b213c3dd8cf8b4da35ff6b9681dd5e4d85f4b1e5a9aef9434bda7034a478e19dacd69793c8daeb4d05bd1ef0d4361042a
7
+ data.tar.gz: 3bc1c652f67bd14794b2dd3538f2187e50d5c27d05877d063da18e8fc0e4f44c91f6c80d07c781f563ea6530f9997eab7206e702c43ac3c6618db5c22280bce5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in morse_mysql_dump.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 fred mcgroarty
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,41 @@
1
+ # MorseMysqlDump
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/morse_mysql_dump`. 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 'morse_mysql_dump'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install morse_mysql_dump
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/morse_mysql_dump.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "morse_mysql_dump"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,86 @@
1
+ require "morse_mysql_dump/version"
2
+
3
+ module Morse
4
+ class MysqlDump
5
+ DUMP_DIR = '/tmp/mysql-backup'
6
+ DUMP_FILE_REGEX = /#{DUMP_DIR}\/dump_[0-9._]{17}\.sql/
7
+ ARCHIVE_FILE_REGEX = /#{DUMP_DIR}\/dump_[0-9._]{17}\.tar\.gz/
8
+
9
+ attr_reader :archive_file
10
+ attr_reader :dump_file
11
+
12
+ def clean!
13
+ FileUtils.rm_rf @temp_dir
14
+ true
15
+ rescue
16
+ false
17
+ end
18
+
19
+ def fake_rails_env
20
+ { database: '', username: '', password: '' }
21
+ end
22
+
23
+ def initialize
24
+ return self if load_db_config and prepare_dump_paths
25
+ nil
26
+ end
27
+
28
+ def rails_root
29
+ defined?(Rails) ? Rails.root : '/tmp'
30
+ end
31
+
32
+ def rails_env
33
+ rails_env ||= defined?(Rails) ? Rails.env : fake_rails_env
34
+ end
35
+
36
+ def dump!
37
+ FileUtils.mkdir_p @temp_dir
38
+ system dump_command
39
+ if File.exists? @dump_file
40
+ # temporary changes pwd
41
+ Dir.chdir(@temp_dir) { |path| system tar_command }
42
+ return File.exists?(@archive_file) ? @archive_file : nil
43
+ end
44
+ end
45
+
46
+
47
+ private
48
+
49
+ def load_db_config
50
+ db_conf_file = File.join(rails_root, "/config/database.yml")
51
+ @db_config = YAML::load(IO.read(db_conf_file))
52
+ @mysql_database = @db_config[rails_env]["database"]
53
+ @mysql_user = @db_config[rails_env]["username"]
54
+ @mysql_password = @db_config[rails_env]["password"]
55
+ true
56
+ rescue
57
+ false
58
+ end
59
+
60
+ def prepare_dump_paths
61
+ time_str = Time.now.strftime('%d.%m.%y_%H.%M.%S')
62
+ @temp_dir = File.join(rails_root, DUMP_DIR)
63
+
64
+ @dump_file_name = "dump_#{time_str}.sql"
65
+ @dump_file = File.join(@temp_dir, @dump_file_name)
66
+
67
+ @archive_file_name = "dump_#{time_str}.tar.gz"
68
+ @archive_file = File.join(@temp_dir, @archive_file_name)
69
+ true
70
+ rescue
71
+ false
72
+ end
73
+
74
+ def dump_command
75
+ cmd = "mysqldump #{@mysql_database}"
76
+ cmd << " -u #{@mysql_user}"
77
+ cmd << " -p#{@mysql_password}" if @mysql_password.present?
78
+ cmd << " > #{@dump_file}"
79
+ return cmd
80
+ end
81
+
82
+ def tar_command
83
+ "tar czf #{@archive_file_name} #{@dump_file_name}"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module MorseMysqlDump
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'morse_mysql_dump/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "morse_mysql_dump"
8
+ spec.version = MorseMysqlDump::VERSION
9
+ spec.authors = ["fred mcgroarty"]
10
+ spec.email = ["freddymcgroarty@gmail.com"]
11
+
12
+ spec.summary = %q{Morse Gem allowing mysql dumps within Ruby applications}
13
+ spec.homepage = "https://github.com/morsedigital/morse_mysql_dump"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.5"
25
+ spec.add_development_dependency "coveralls", "~> 0.8"
26
+ spec.add_development_dependency "rb-fsevent", "~> 0.9"
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morse_mysql_dump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fred mcgroarty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-12 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rb-fsevent
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ description:
98
+ email:
99
+ - freddymcgroarty@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/morse_mysql_dump.rb
114
+ - lib/morse_mysql_dump/version.rb
115
+ - morse_mysql_dump.gemspec
116
+ homepage: https://github.com/morsedigital/morse_mysql_dump
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.8
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Morse Gem allowing mysql dumps within Ruby applications
140
+ test_files: []