capistrano-mysqldump 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "capistrano", ">=1.0.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ capistrano (2.8.0)
5
+ highline
6
+ net-scp (>= 1.0.0)
7
+ net-sftp (>= 2.0.0)
8
+ net-ssh (>= 2.0.14)
9
+ net-ssh-gateway (>= 1.1.0)
10
+ git (1.2.5)
11
+ highline (1.6.2)
12
+ jeweler (1.6.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ net-scp (1.0.4)
17
+ net-ssh (>= 1.99.1)
18
+ net-sftp (2.0.5)
19
+ net-ssh (>= 2.0.9)
20
+ net-ssh (2.2.1)
21
+ net-ssh-gateway (1.1.0)
22
+ net-ssh (>= 1.99.1)
23
+ rake (0.9.2.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ capistrano (>= 1.0.0)
31
+ jeweler (~> 1.6.4)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alex Farrill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,57 @@
1
+ = capistrano-mysqldump
2
+
3
+ Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database.
4
+
5
+ WARNING: This will blow away your development database (duh)
6
+
7
+ == Installation
8
+
9
+ gem install capistrano-mysqldump
10
+
11
+ == Usage
12
+
13
+ * In your deploy file:
14
+
15
+ require 'capistrano/mysqldump'
16
+
17
+ * Run:
18
+
19
+ cap mysqldump
20
+
21
+ Or if you're using capistrano-ext/multistage, do
22
+
23
+ cap production mysqldump
24
+
25
+ Or whatever environment you want to take the mysqldump from
26
+
27
+ == Configuration
28
+
29
+ Override these defaults in deploy.rb if necessary
30
+
31
+ * Location of the mysqldump binary
32
+ set :mysqldump_bin, "/usr/local/mysql/bin/mysqldump"
33
+
34
+ * Where on the remote machine to dump the sql dump file
35
+ set :mysqldump_remote_tmp_dir, "/tmp"
36
+
37
+ * Where on the local machine to download the sql dump file from the remote machine
38
+ set :mysqldump_local_tmp_dir, "/tmp"
39
+
40
+ * Where to run the mysqldump command. If set to :local, mysqldump will use the -h parameter and run the dump locally. The default is set to :local if a host is specified, otherwise it is set to :remote
41
+ set :mysqldump_location, :local
42
+
43
+ == Contributing to capistrano-mysqldump
44
+
45
+ * Contributions welcome
46
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
47
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
48
+ * Fork the project
49
+ * Start a feature/bugfix branch
50
+ * Commit and push until you are happy with your contribution
51
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
52
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
53
+
54
+ == Copyright
55
+
56
+ Copyright (c) 2011 Alex Farrill. See LICENSE.txt for
57
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "capistrano-mysqldump"
18
+ gem.homepage = "http://github.com/alexfarrill/capistrano-mysqldump"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database}
21
+ gem.description = %Q{}
22
+ gem.email = "alex.farrill@gmail.com"
23
+ gem.authors = ["Alex Farrill"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ # end
42
+
43
+ task :default => :test
44
+
45
+ # require 'rake/rdoctask'
46
+ # Rake::RDocTask.new do |rdoc|
47
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+ #
49
+ # rdoc.rdoc_dir = 'rdoc'
50
+ # rdoc.title = "capistrano-mysqldump #{version}"
51
+ # rdoc.rdoc_files.include('README*')
52
+ # rdoc.rdoc_files.include('lib/**/*.rb')
53
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.8
@@ -0,0 +1,66 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :mysqldump do
3
+ task :default, :roles => :db do
4
+ dump
5
+ import
6
+ end
7
+
8
+ task :setup do
9
+ set :mysqldump_config, YAML.load_file("config/database.yml")[rails_env.to_s]
10
+ host = mysqldump_config["host"]
11
+
12
+ # overwrite these if necessary
13
+ set :mysqldump_bin, "/usr/local/mysql/bin/mysqldump" unless exists?(:mysqldump_bin)
14
+ set :mysqldump_remote_tmp_dir, "/tmp" unless exists?(:mysqldump_remote_tmp_dir)
15
+ set :mysqldump_local_tmp_dir, "/tmp" unless exists?(:mysqldump_local_tmp_dir)
16
+ set :mysqldump_location, host && host.any? && host != "localhost" ? :local : :remote unless exists?(:mysqldump_location)
17
+
18
+ # for convenience
19
+ set :mysqldump_filename, "%s-%s.sql" % [application, Time.now.to_i]
20
+ set :mysqldump_filename_gz, "%s.gz" % mysqldump_filename
21
+ set :mysqldump_remote_filename, File.join( mysqldump_remote_tmp_dir, mysqldump_filename_gz )
22
+ set :mysqldump_local_filename, File.join( mysqldump_local_tmp_dir, mysqldump_filename )
23
+ set :mysqldump_local_filename_gz, File.join( mysqldump_local_tmp_dir, mysqldump_filename_gz )
24
+ end
25
+
26
+ task :dump, :roles => :db do
27
+ setup
28
+ username, password, database, host = mysqldump_config.values_at *%w( username password database host )
29
+
30
+ mysqldump_cmd = "%s --quick --single-transaction" % mysqldump_bin
31
+ mysqldump_cmd += " -h #{host}" if host && host.any?
32
+
33
+ case mysqldump_location
34
+ when :remote
35
+ mysqldump_cmd += " -u %s -p %s" % [ username, database ]
36
+ mysqldump_cmd += " | gzip > %s" % mysqldump_remote_filename
37
+
38
+ run mysqldump_cmd do |ch, stream, out|
39
+ ch.send_data "#{password}\n" if out =~ /^Enter password:/
40
+ end
41
+
42
+ download mysqldump_remote_filename, mysqldump_local_filename_gz, :via => :scp
43
+ run "rm #{mysqldump_remote_filename}"
44
+
45
+ `gunzip #{mysqldump_local_filename_gz}`
46
+ when :local
47
+ mysqldump_cmd += " -u %s" % username
48
+ mysqldump_cmd += " -p#{password}" if password && password.any?
49
+ mysqldump_cmd += " %s > %s" % [ database, mysqldump_local_filename]
50
+
51
+ `#{mysqldump_cmd}`
52
+ end
53
+ end
54
+
55
+ task :import do
56
+ config = YAML.load_file("config/database.yml")["development"]
57
+ username, password, database = config.values_at *%w( username password database )
58
+
59
+ mysql_cmd = "mysql -u#{username}"
60
+ mysql_cmd += " -p#{password}" if password && password.any?
61
+ `#{mysql_cmd} -e "drop database #{database}; create database #{database}"`
62
+ `#{mysql_cmd} #{database} < #{mysqldump_local_filename}`
63
+ `rm #{mysqldump_local_filename}`
64
+ end
65
+ end
66
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'capistrano-mysqldump'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCapistranoMysqldump < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-mysqldump
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 8
10
+ version: 1.0.8
11
+ platform: ruby
12
+ authors:
13
+ - Alex Farrill
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ version_requirements: *id001
35
+ name: capistrano
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ version_requirements: *id002
51
+ name: bundler
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 4
65
+ version: 1.6.4
66
+ version_requirements: *id003
67
+ name: jeweler
68
+ description: ""
69
+ email: alex.farrill@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README
77
+ files:
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README
82
+ - Rakefile
83
+ - VERSION
84
+ - lib/capistrano/mysqldump.rb
85
+ - test/helper.rb
86
+ - test/test_capistrano-mysqldump.rb
87
+ homepage: http://github.com/alexfarrill/capistrano-mysqldump
88
+ licenses:
89
+ - MIT
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.11
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Capistrano extension to run mysqldump remotely, download, and import into your local Rails development database
120
+ test_files: []
121
+