Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updates for bundler; version 1.2.1

  • Loading branch information...
commit f0e7cc9156f0bdb1d2c7ed430260c6a1daa8aee8 1 parent c7934f9
@smtlaissezfaire authored
View
12 README.rdoc
@@ -6,15 +6,15 @@ your local machine.
== INSTALLATION
-Install the plugin in vendor/plugins:
+1. Install the gem in bundler's Gemfile:
- # FROM RAILS_ROOT
- git submodule add git://github.com/smtlaissezfaire/cap_db_dump.git vendor/plugins/cap_db_dump
+ gem 'cap_db_dump'
-Or without submodules:
+ $ bundle install
- # FROM RAILS_ROOT
- ruby script/plugin install git://github.com/smtlaissezfaire/cap_db_dump.git
+2. Require the gem in the cap file:
+
+ require 'cap_db_dump'
Finally, add the :db_dump => true flag on the server where you'd like the mysqldump to run:
View
2  VERSION
@@ -1 +1 @@
-1.2.0
+1.2.1
View
4 cap_db_dump.gemspec
@@ -1,12 +1,12 @@
Gem::Specification.new do |s|
s.name = 'cap_db_dump'
- s.version = '1.2.0'
+ s.version = '1.2.1'
s.date = '2012-09-06'
s.summary = "cap_db_dump"
s.description = "Capistrano tasks for dumping your mysql database + transfering to your local machine"
s.authors = ["Scott Taylor"]
s.email = 'scott@railsnewbie.com'
- s.files = Dir.glob("recipes/**/*.rb")
+ s.files = Dir.glob("lib/**/*.rb")
s.homepage =
'https://github.com/smtlaissezfaire/cap_db_dump'
end
View
109 lib/cap_db_dump.rb
@@ -0,0 +1,109 @@
+Capistrano::Configuration.instance(:must_exist).load do
+ namespace :database do
+ # a list of tables for which only the schema, but no data should be dumped.
+ set :schema_only_tables, []
+ set :dump_root_path, "/tmp"
+ set :formatted_time, Time.now.utc.strftime("%Y-%m-%d-%H:%M:%S")
+
+ module CapDbDumpHelpers
+ def dump_path
+ "#{dump_root_path}/#{database_name}_dump_#{formatted_time}.sql"
+ end
+
+ def give_description(desc_string)
+ puts " ** #{desc_string}"
+ end
+
+ def database_name
+ database_yml_in_env["database"]
+ end
+
+ def database_username
+ database_yml_in_env["username"]
+ end
+
+ def database_host
+ database_yml_in_env["host"] || "localhost"
+ end
+
+ def database_password
+ database_yml_in_env["password"]
+ end
+
+ def database_yml_in_env
+ database_yml[rails_env]
+ end
+
+ def database_yml
+ @database_yml ||= read_db_yml
+ end
+
+ def tasks_matching_for_db_dump
+ { :only => { :db_dump => true } }
+ end
+ end
+
+ extend CapDbDumpHelpers
+
+ task :read_db_yml, tasks_matching_for_db_dump do
+ @database_yml ||= begin
+ yaml = capture("cat #{shared_path}/config/database.yml")
+ YAML.load(yaml)
+ end
+ end
+
+ def password_field
+ database_password && database_password.length > 0 ? "-p#{database_password}" : ""
+ end
+
+ task :create_dump, tasks_matching_for_db_dump do
+ ignored_tables = schema_only_tables.map { |table_name|
+ "--ignore-table=#{database_name}.#{table_name}"
+ }
+
+ ignored_tables = ignored_tables.join(" ")
+
+ command = "mysqldump -u #{database_username} -h #{database_host} #{password_field} -Q "
+ command << "--add-drop-table -O add-locks=FALSE --lock-tables=FALSE --single-transaction "
+ command << "#{ignored_tables} #{database_name} > #{dump_path}"
+
+ give_description "About to dump production DB"
+
+ run command
+ dump_schema_tables if schema_only_tables.any?
+ end
+
+ task :dump_schema_tables, tasks_matching_for_db_dump do
+ if schema_only_tables.any?
+ table_names = schema_only_tables.join(" ")
+
+ command = "mysqldump -u #{database_username} -h #{database_host} #{password_field} "
+ command << "-Q --add-drop-table --single-transaction --no-data #{database_name} #{table_names} >> #{dump_path}"
+
+ give_description "Dumping schema for tables: #{schema_only_tables.join(", ")}"
+ run command
+ end
+ end
+
+ desc "Create a dump of the production database"
+ task :dump, tasks_matching_for_db_dump do
+ create_dump
+
+ cmd = "gzip -9 #{dump_path}"
+
+ give_description "Gzip'ing the file"
+ run cmd
+ end
+
+ desc "Make a production dump, transfer it to this machine"
+ task :dump_and_transfer, tasks_matching_for_db_dump do
+ dump
+ transfer
+ end
+
+ task :transfer, tasks_matching_for_db_dump do
+ give_description "Grabbing the dump"
+ download("#{dump_path}.gz", ".", :via => :scp)
+ end
+ end
+end
View
107 recipes/cap_db_dump.rb
@@ -1,107 +0,0 @@
-namespace :database do
- # a list of tables for which only the schema, but no data should be dumped.
- set :schema_only_tables, []
- set :dump_root_path, "/tmp"
- set :formatted_time, Time.now.utc.strftime("%Y-%m-%d-%H:%M:%S")
-
- module CapDbDumpHelpers
- def dump_path
- "#{dump_root_path}/#{database_name}_dump_#{formatted_time}.sql"
- end
-
- def give_description(desc_string)
- puts " ** #{desc_string}"
- end
-
- def database_name
- database_yml_in_env["database"]
- end
-
- def database_username
- database_yml_in_env["username"]
- end
-
- def database_host
- database_yml_in_env["host"] || "localhost"
- end
-
- def database_password
- database_yml_in_env["password"]
- end
-
- def database_yml_in_env
- database_yml[rails_env]
- end
-
- def database_yml
- @database_yml ||= read_db_yml
- end
-
- def tasks_matching_for_db_dump
- { :only => { :db_dump => true } }
- end
- end
-
- extend CapDbDumpHelpers
-
- task :read_db_yml, tasks_matching_for_db_dump do
- @database_yml ||= begin
- yaml = capture("cat #{shared_path}/config/database.yml")
- YAML.load(yaml)
- end
- end
-
- def password_field
- database_password && database_password.any? ? "-p#{database_password}" : ""
- end
-
- task :create_dump, tasks_matching_for_db_dump do
- ignored_tables = schema_only_tables.map { |table_name|
- "--ignore-table=#{database_name}.#{table_name}"
- }
-
- ignored_tables = ignored_tables.join(" ")
-
- command = "mysqldump -u #{database_username} -h #{database_host} #{password_field} -Q "
- command << "--add-drop-table -O add-locks=FALSE --lock-tables=FALSE --single-transaction "
- command << "#{ignored_tables} #{database_name} > #{dump_path}"
-
- give_description "About to dump production DB"
-
- run command
- dump_schema_tables if schema_only_tables.any?
- end
-
- task :dump_schema_tables, tasks_matching_for_db_dump do
- if schema_only_tables.any?
- table_names = schema_only_tables.join(" ")
-
- command = "mysqldump -u #{database_username} -h #{database_host} #{password_field} "
- command << "-Q --add-drop-table --single-transaction --no-data #{database_name} #{table_names} >> #{dump_path}"
-
- give_description "Dumping schema for tables: #{schema_only_tables.join(", ")}"
- run command
- end
- end
-
- desc "Create a dump of the production database"
- task :dump, tasks_matching_for_db_dump do
- create_dump
-
- cmd = "gzip -9 #{dump_path}"
-
- give_description "Gzip'ing the file"
- run cmd
- end
-
- desc "Make a production dump, transfer it to this machine"
- task :dump_and_transfer, tasks_matching_for_db_dump do
- dump
- transfer
- end
-
- task :transfer, tasks_matching_for_db_dump do
- give_description "Grabbing the dump"
- download("#{dump_path}.gz", ".", :via => :scp)
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.