capistrano-mysql 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1edbcf5e667e10ed6754b0c7c161c98e571d7904
4
+ data.tar.gz: 7a0af507b3b0b5077bc9d4d278c62e56f2d36a58
5
+ SHA512:
6
+ metadata.gz: a0d6b05de83f4447bbedb2a7f9a2fb3c684093a42494381a4d5342c346b71d87cdb284b5f683c3cade69ae82ee9bb682237e64703cc7c49f269198877836980f
7
+ data.tar.gz: be28bb1953f598d07e8f3c9f06fc22dc4c98b725dbaa750978e5c619293b13dca3fe5853156bed8a187eab8a102eaf35668151c1a7937b60e5d8adbafb6841cf
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ nbproject
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-mysql.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 André Lademann
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Capistrano::Mysql
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-mysql'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-mysql
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/mysql/version'
5
+
6
+ # gemspec :development_group => :dev
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "capistrano-mysql"
10
+ spec.version = Capistrano::Mysql::VERSION
11
+ spec.authors = ["André Lademann"]
12
+ spec.email = ["andre@programmerq.eu"]
13
+ spec.description = %q{Deploy mysql databases}
14
+ spec.summary = %q{Deploy mysql databases}
15
+ spec.homepage = "http://github.com/programmerqeu/capistrano-mysql"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "capistrano", ">= 2.13.5","<= 2.15.4"
24
+ spec.add_dependency "capistrano_colors", ">= 0.5.5"
25
+ spec.add_dependency "capistrano-ext", ">= 1.2.1"
26
+ spec.add_dependency "railsless-deploy", "~> 1.1.2"
27
+ spec.add_dependency "ruby-progressbar", "1.0.2"
28
+
29
+ spec.add_development_dependency "railsless-deploy", "~> 1.1.2"
30
+ spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "rake"
32
+ end
@@ -0,0 +1,121 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "capistrano/ext/multistage requires Capistrano 2"
3
+ end
4
+
5
+ ################################################################################
6
+ ## Backup
7
+ ###############################################################################
8
+
9
+ require "capistrano/mysql/version"
10
+ require 'capistrano/recipes/deploy/scm'
11
+ require 'capistrano/recipes/deploy/strategy'
12
+ require "fileutils"
13
+ require 'yaml'
14
+
15
+ # PHP binary to execute
16
+ set :deploy_env, "staging"
17
+
18
+ namespace :mysql do
19
+
20
+ desc "Dev Task"
21
+
22
+ task :dev, :roles => :db, :only => { :primary => true } do
23
+ databaseCrendentials = YAML::load(IO.read('config/database.yml'))
24
+ puts databaseCrendentials[fetch(:deploy_env, "staging")]['database']
25
+ #ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
26
+ end
27
+
28
+ desc "creating a database backup of the current environment"
29
+ task :backup, :roles => :db, :only => { :primary => true } do
30
+ file = "#{application_root}#{backup_dir}sql/#{stage_current}_dump.sql"
31
+ set :file, file
32
+ # if stage_current == 'staging'
33
+ # transaction do
34
+ # puts "Check if backup directory exists: "
35
+ # run "mkdir -p #{application_root}#{backup_dir}sql/", :once => true
36
+ # puts "Create a backup of the existing dumps: "
37
+ # run "if [[ -d #{file} ]]; then cp -b #{file} #{file}.backup; fi"
38
+ # puts "Create a database backup for \"#{stage_current}\" enviroment:"
39
+ # run "mysqldump -u #{database_username} -h #{database_host} --add-drop-table --password=#{database_password} #{database_dbname} --default-character-set='utf8' > #{file};"
40
+ # run "chmod 650 #{file};"
41
+ # puts "\nDie Datei ist zu finden unter \e[1;46m\"#{file}\" \e[0m.\n"
42
+ # end
43
+ # elsif stage_current == 'development'
44
+ # transaction do
45
+ # puts 'Prüfen ob Backup-Verzeichnis vorhanden ist:'
46
+ # run_locally "mkdir -p #{application_root}#{backup_dir}sql/"
47
+ # puts "Sicherung des vorhanden Dumps erstellen:"
48
+ # run_locally "if [[ -d #{file} ]]; then cp -b #{file} #{file}.backup; fi"
49
+ # puts "Datenbank-Dump für \"#{stage_current}\" erstellen:"
50
+ # run_locally "mysqldump -u #{database_username} -h #{database_host} --add-drop-table --password=#{database_password} #{database_dbname} --default-character-set='utf8' > #{file};"
51
+ # puts "\nDie Datei ist zu finden unter \e[1;46m\"#{file}\" \e[0m.\n"
52
+ # end
53
+ # end
54
+ end
55
+
56
+
57
+ desc "Pull a database backup of the current environment to local"
58
+ task :pull, :roles => :db, :only => { :primary => true } do
59
+ end
60
+
61
+ desc "Pull a database backup of the one environment to onother"
62
+ task :pullto, :roles => :db, :only => { :primary => true } do
63
+ end
64
+
65
+ desc "Push a local database backup to the current environment"
66
+ task :push, :roles => :db, :only => { :primary => true } do
67
+ end
68
+
69
+ desc "Move a database backup of the one environment to another"
70
+ task :move, :roles => :db, :only => { :primary => true } do
71
+
72
+ env = fetch(:deploy_env, "remote")
73
+ filename = "#{application}.#{env}_dump.latest.sql.gz"
74
+ config = load_database_config IO.read("#{app_config_path}/#{app_config_file}"), symfony_env_local
75
+ sqlfile = "#{application}_dump.sql"
76
+
77
+ database.dump.remote
78
+
79
+ f = File.new("backups/#{sqlfile}", "a+")
80
+ gz = Zlib::GzipReader.new(File.open("backups/#{filename}", "r"))
81
+ f << gz.read
82
+ f.close
83
+
84
+ case config['database_driver']
85
+ when "pdo_mysql", "mysql"
86
+ `mysql -u#{config['database_user']} --password=\"#{config['database_password']}\" #{config['database_name']} < backups/#{sqlfile}`
87
+ when "pdo_pgsql", "pgsql"
88
+ `PGPASSWORD=\"#{config['database_password']}\" psql -U #{config['database_user']} #{config['database_name']} < backups/#{sqlfile}`
89
+ end
90
+ FileUtils.rm("backups/#{sqlfile}")
91
+ end
92
+
93
+ desc "Dumps local database, loads it to remote, and populates there"
94
+ task :to_remote, :roles => :db, :only => { :primary => true } do
95
+ filename = "#{application}.local_dump.latest.sql.gz"
96
+ file = "backups/#{filename}"
97
+ sqlfile = "#{application}_dump.sql"
98
+ config = ""
99
+
100
+ database.dump.local
101
+
102
+ upload(file, "#{remote_tmp_dir}/#{filename}", :via => :scp)
103
+ run "#{try_sudo} gunzip -c #{remote_tmp_dir}/#{filename} > #{remote_tmp_dir}/#{sqlfile}"
104
+
105
+ data = capture("#{try_sudo} cat #{current_path}/#{app_config_path}/#{app_config_file}")
106
+ config = load_database_config data, symfony_env_prod
107
+
108
+ case config['database_driver']
109
+ when "pdo_mysql", "mysql"
110
+ data = capture("#{try_sudo} mysql -u#{config['database_user']} --host='#{config['database_host']}' --password='#{config['database_password']}' #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}")
111
+ puts data
112
+ when "pdo_pgsql", "pgsql"
113
+ data = capture("#{try_sudo} PGPASSWORD=\"#{config['database_password']}\" psql -U #{config['database_user']} #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}")
114
+ puts data
115
+ end
116
+
117
+ run "#{try_sudo} rm -f #{remote_tmp_dir}/#{filename}"
118
+ run "#{try_sudo} rm -f #{remote_tmp_dir}/#{sqlfile}"
119
+
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Mysql
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - André Lademann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.13.5
20
+ - - <=
21
+ - !ruby/object:Gem::Version
22
+ version: 2.15.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.5
30
+ - - <=
31
+ - !ruby/object:Gem::Version
32
+ version: 2.15.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: capistrano_colors
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.5.5
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.5.5
47
+ - !ruby/object:Gem::Dependency
48
+ name: capistrano-ext
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.2.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: railsless-deploy
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.1.2
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: ruby-progressbar
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '='
80
+ - !ruby/object:Gem::Version
81
+ version: 1.0.2
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '='
87
+ - !ruby/object:Gem::Version
88
+ version: 1.0.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: railsless-deploy
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 1.1.2
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 1.1.2
103
+ - !ruby/object:Gem::Dependency
104
+ name: bundler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.3'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: '1.3'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description: Deploy mysql databases
132
+ email:
133
+ - andre@programmerq.eu
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - .gitignore
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - capistrano-mysql.gemspec
144
+ - lib/capistrano/mysql.rb
145
+ - lib/capistrano/mysql/version.rb
146
+ homepage: http://github.com/programmerqeu/capistrano-mysql
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.0.3
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Deploy mysql databases
170
+ test_files: []