capistrano_misc_recipes 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/capistrano_misc_recipes/console.rb +1 -1
- data/lib/capistrano_misc_recipes/db_dump.rb +57 -0
- data/lib/capistrano_misc_recipes/dbfetch.rb +37 -0
- data/lib/capistrano_misc_recipes/tasks.rb +50 -0
- data/lib/capistrano_misc_recipes/version.rb +1 -1
- data/lib/capistrano_misc_recipes.rb +1 -0
- metadata +8 -4
data/README.md
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module CapistranoMiscRecipes
|
2
|
+
module DbDump
|
3
|
+
def DbDump.command options
|
4
|
+
dump_file, dump_command = options['dump_file'], []
|
5
|
+
|
6
|
+
case options["adapter"]
|
7
|
+
when /^mysql/
|
8
|
+
args = {
|
9
|
+
'host' => '--host',
|
10
|
+
'port' => '--port',
|
11
|
+
'socket' => '--socket',
|
12
|
+
'username' => '--user',
|
13
|
+
'encoding' => '--default-character-set',
|
14
|
+
'sslca' => '--ssl-ca',
|
15
|
+
'sslcert' => '--ssl-cert',
|
16
|
+
'sslcapath' => '--ssl-capath',
|
17
|
+
'sslcipher' => '--ssh-cipher',
|
18
|
+
'sslkey' => '--ssl-key'
|
19
|
+
}.map { |opt, arg| "#{arg}=#{options[opt]}" if options[opt] }.compact
|
20
|
+
|
21
|
+
if options['password'] && !options['password'].to_s.empty?
|
22
|
+
args << "--password=#{options['password']}"
|
23
|
+
end
|
24
|
+
|
25
|
+
args << options['database']
|
26
|
+
dump_command << 'mysqldump' << args
|
27
|
+
|
28
|
+
when /^postgres/
|
29
|
+
args = {
|
30
|
+
'host' => '--host',
|
31
|
+
'port' => '--port',
|
32
|
+
'username' => '--user',
|
33
|
+
'encoding' => '--encoding',
|
34
|
+
}.map { |opt, arg| "#{arg}=#{options[opt]}" if options[opt] }.compact
|
35
|
+
|
36
|
+
args << options['database']
|
37
|
+
dump_command << "pg_dump --clean --no-owner" << args
|
38
|
+
# TODO password
|
39
|
+
|
40
|
+
else
|
41
|
+
abort "Unknown command-line client for #{options['database']}"
|
42
|
+
end
|
43
|
+
|
44
|
+
case options['pack']
|
45
|
+
when 'bzip2' ; dump_command << '| bzip2 -c'
|
46
|
+
when 'gzip' ; dump_command << '| gzip'
|
47
|
+
end
|
48
|
+
|
49
|
+
dump_command << '>'
|
50
|
+
|
51
|
+
dump_command << dump_file
|
52
|
+
dump_command = dump_command.join ' '
|
53
|
+
|
54
|
+
return dump_command
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Recipe for fetch db dump from server
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'erb'
|
5
|
+
require 'capistrano_misc_recipes/db_dump'
|
6
|
+
|
7
|
+
module Capistrano
|
8
|
+
module Console
|
9
|
+
Configuration.instance(true).load do
|
10
|
+
|
11
|
+
desc 'fetch db dump from the server'
|
12
|
+
task :dbfetch, roles: :db, only: { primary: true } do
|
13
|
+
|
14
|
+
# TODO extract main loginc to lib to reuse in rake task
|
15
|
+
|
16
|
+
database_yml = capture "cat #{current_path}/config/database.yml"
|
17
|
+
config = begin
|
18
|
+
YAML.load(ERB.new(database_yml).result)[rails_env]
|
19
|
+
rescue
|
20
|
+
# TODO error report if database.yml not exists unreachable!
|
21
|
+
end
|
22
|
+
|
23
|
+
dump_file = "/tmp/#{ capture("hostname").chomp }-#{ config['database'] }-#{ Time.now.strftime('%Y-%m-%d-%H-%M-%S') }.sql.bz2"
|
24
|
+
|
25
|
+
on_rollback { run "rm -f #{dump_file}" }
|
26
|
+
|
27
|
+
dump_command = ::CapistranoMiscRecipes::DbDump.command(config.merge 'dump_file' => dump_file, 'pack' => 'bzip2' )
|
28
|
+
|
29
|
+
puts dump_command
|
30
|
+
run dump_command
|
31
|
+
download dump_file, File.basename(dump_file)
|
32
|
+
run "rm -f #{dump_file}"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'capistrano_misc_recipes/db_dump'
|
3
|
+
|
4
|
+
namespace :db do
|
5
|
+
|
6
|
+
# optinoal parametrs
|
7
|
+
# store_path - path to store dump file
|
8
|
+
# dump_file - file name
|
9
|
+
# without_timestamp - skip adding time stamp to file name if set to 'y'
|
10
|
+
# ignore_tables - do not dump given tables
|
11
|
+
|
12
|
+
desc 'native SQL dump of database defined in config/database.yml for the current RAILS_ENV'
|
13
|
+
task :sqldump => :environment do
|
14
|
+
dump_database
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :sqldump do
|
18
|
+
desc 'packed with gzip native SQL dump of database defined in config/database.yml for the current RAILS_ENV'
|
19
|
+
task :gzip => :environment do
|
20
|
+
dump_database 'gzip'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'packed with bzip2 native SQL dump of database defined in config/database.yml for the current RAILS_ENV'
|
24
|
+
task :bzip2 => :environment do
|
25
|
+
dump_database 'bzip2'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump_database pack=nil
|
30
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
31
|
+
|
32
|
+
raise "Destination directory do not exists" if !ENV['store_path'].blank? && !File.exists?(File.expand_path(ENV['store_path']))
|
33
|
+
|
34
|
+
store_path = !ENV['store_path'].blank? ? File.expand_path(ENV['store_path']) : '.'
|
35
|
+
dump_file = !ENV['dump_file'].blank? ? ENV['dump_file'].dup : "#{`hostname`.chomp}-#{config['database']}"
|
36
|
+
dump_file << '-' + Time.now.strftime('%Y-%m-%d-%H-%M-%S') unless !ENV['without_timestamp'].blank? && ENV['without_timestamp'].downcase == 'y'
|
37
|
+
dump_file << '.sql'
|
38
|
+
|
39
|
+
case pack
|
40
|
+
when 'gzip' ; dump_file << '.gz'
|
41
|
+
when 'bzip2' ; dump_file << '.bz2'
|
42
|
+
end
|
43
|
+
file = File.expand_path(File.join(store_path, dump_file))
|
44
|
+
|
45
|
+
command = ::CapistranoMiscRecipes::DbDump.command config.merge('pack' => pack, 'dump_file' => dump_file)
|
46
|
+
|
47
|
+
puts command
|
48
|
+
system command
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capistrano_misc_recipes/tasks'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano_misc_recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -74,7 +74,11 @@ files:
|
|
74
74
|
- README.md
|
75
75
|
- Rakefile
|
76
76
|
- capistrano_misc_recipes.gemspec
|
77
|
+
- lib/capistrano_misc_recipes.rb
|
77
78
|
- lib/capistrano_misc_recipes/console.rb
|
79
|
+
- lib/capistrano_misc_recipes/db_dump.rb
|
80
|
+
- lib/capistrano_misc_recipes/dbfetch.rb
|
81
|
+
- lib/capistrano_misc_recipes/tasks.rb
|
78
82
|
- lib/capistrano_misc_recipes/version.rb
|
79
83
|
homepage: http://github.com/corlinus/capistrano_misc_recipes
|
80
84
|
licenses:
|
@@ -91,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
95
|
version: '0'
|
92
96
|
segments:
|
93
97
|
- 0
|
94
|
-
hash:
|
98
|
+
hash: 873591735516740147
|
95
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
100
|
none: false
|
97
101
|
requirements:
|
@@ -100,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
104
|
version: '0'
|
101
105
|
segments:
|
102
106
|
- 0
|
103
|
-
hash:
|
107
|
+
hash: 873591735516740147
|
104
108
|
requirements: []
|
105
109
|
rubyforge_project:
|
106
110
|
rubygems_version: 1.8.25
|