capobvious 0.3.pre4 → 0.3.pre5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  Capistrano::Configuration.instance(:must_exist).load do
2
2
  def database_yml(env = rails_env)
3
+ require 'yaml'
3
4
  yml = File.read(fetch(:database_yml_path))
4
5
  config = YAML::load(yml)[env.to_s]
5
6
  config.keys.each do |key|
@@ -7,29 +8,28 @@ Capistrano::Configuration.instance(:must_exist).load do
7
8
  end
8
9
  config
9
10
  end
11
+
12
+
10
13
  namespace :backup do
11
- desc "Backup a database"
12
- task :db do
14
+ task :db_ssh do
15
+ command = []
13
16
  yml = database_yml
14
17
  file_name = fetch(:db_file_name)
15
- archive_ext = fetch(:db_archive_ext)
16
- dump_file_path = "#{shared_path}/backup/#{file_name}"
17
- output_file = "#{file_name}.#{archive_ext}"
18
- output_file_path = "#{dump_file_path}.#{archive_ext}"
19
- require 'yaml'
20
- run "mkdir -p #{shared_path}/backup"
18
+
21
19
  if yml[:adapter] == "postgresql"
22
- logger.important("Backup database #{yml[:database]}", "Backup:db")
23
- run "export PGPASSWORD=\"#{yml[:password]}\" && pg_dump -U #{yml[:username]} #{yml[:database]} > #{dump_file_path}"
24
- run "cd #{shared_path}/backup && #{arch_create} #{output_file} #{file_name} && rm #{dump_file_path}"
20
+ logger.info("Backup database #{yml[:database]}", "Backup:db")
21
+ command << "export PGPASSWORD=\"#{yml[:password]}\""
22
+ command << "pg_dump -U #{yml[:username]} #{yml[:database]} | bzip2 -c | cat"
25
23
  else
26
24
  puts "Cannot backup, adapter #{yml[:adapter]} is not implemented for backup yet"
27
25
  end
28
- system "mkdir -p #{backup_folder_path}"
29
- download_path = "#{backup_folder_path}/#{file_name}.#{archive_ext}"
30
- logger.important("Downloading database to #{download_path}", "Backup:db")
31
- download(output_file_path, download_path)
32
- run "rm -v #{output_file_path}" if fetch(:del_backup)
26
+
27
+ download_path = "#{backup_folder_path}/#{file_name}.bz2"
28
+ logger.info("Saving database dump to #{download_path}", "Backup:db")
29
+ system "#{ssh} '#{command.join(' && ')}' > #{download_path}"
30
+ end
31
+ #ssh 192.168.1.5 'tar -C $HOME -cvj www | cat' > www.bz2
32
+ task :sys_ssh do
33
33
  end
34
34
  desc "Backup public/system folder"
35
35
  task :sys do
@@ -49,6 +49,28 @@ Capistrano::Configuration.instance(:must_exist).load do
49
49
  task :clean do
50
50
  run "rm -rfv #{shared_path}/backup/*"
51
51
  end
52
+ desc "Backup a database"
53
+ task :db do
54
+ yml = database_yml
55
+ file_name = fetch(:db_file_name)
56
+ archive_ext = fetch(:db_archive_ext)
57
+ dump_file_path = "#{shared_path}/backup/#{file_name}"
58
+ output_file = "#{file_name}.#{archive_ext}"
59
+ output_file_path = "#{dump_file_path}.#{archive_ext}"
60
+ run "mkdir -p #{shared_path}/backup"
61
+ if yml[:adapter] == "postgresql"
62
+ logger.important("Backup database #{yml[:database]}", "Backup:db")
63
+ run "export PGPASSWORD=\"#{yml[:password]}\" && pg_dump -U #{yml[:username]} #{yml[:database]} > #{dump_file_path}"
64
+ run "cd #{shared_path}/backup && #{arch_create} #{output_file} #{file_name} && rm #{dump_file_path}"
65
+ else
66
+ puts "Cannot backup, adapter #{yml[:adapter]} is not implemented for backup yet"
67
+ end
68
+ system "mkdir -p #{backup_folder_path}"
69
+ download_path = "#{backup_folder_path}/#{file_name}.#{archive_ext}"
70
+ logger.important("Downloading database to #{download_path}", "Backup:db")
71
+ download(output_file_path, download_path)
72
+ run "rm -v #{output_file_path}" if fetch(:del_backup)
73
+ end
52
74
  end
53
75
  if exists?(:backup_db) && fetch(:backup_db) == true
54
76
  before "deploy:update", "backup:db"
@@ -24,10 +24,10 @@ Capistrano::Configuration.instance(:must_exist).load do
24
24
 
25
25
  set :timestamp, Time.new.to_i.to_s
26
26
  set :db_archive_ext, "tar.bz2"
27
- set :arch_extract, "tar -xvjf"
28
- set :arch_create, "tar -cvjf"
27
+ _cset :arch_extract, "tar -xvjf"
28
+ _cset :arch_create, "tar -cvjf"
29
29
 
30
- set :db_file_name, "#{fetch(:application)}-#{timestamp}.sql"
30
+ set :db_file_name, "#{fetch(:application)}_#{fetch(:rails_env)}-#{timestamp}.sql"
31
31
  set :sys_file_name, "#{application}-system-#{timestamp}.#{db_archive_ext}"
32
32
 
33
33
  namespace :db do
@@ -43,6 +43,17 @@ Capistrano::Configuration.instance(:must_exist).load do
43
43
  end
44
44
  end
45
45
 
46
+ task :flush do
47
+ yml = database_yml
48
+ if yml[:adapter] == "postgresql"
49
+ sql = %|drop schema public cascade; create schema public;ALTER SCHEMA public OWNER TO #{yml[:username]};|
50
+ sql+= %|CREATE EXTENSION IF NOT EXISTS hstore;| if exists?(:hstore) && fetch(:hstore) == true
51
+ run "echo \"#{sql}\" | #{sudo} -u postgres psql #{yml[:database]}"
52
+ else
53
+ puts "Cannot flush, adapter #{yml[:adapter]} is not implemented yet"
54
+ end
55
+ end
56
+
46
57
  [:seed, :migrate].each do |t|
47
58
  task t do
48
59
  run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:#{t}"
@@ -11,6 +11,7 @@ Capistrano::Configuration.instance(:must_exist).load do
11
11
  _cset :backup_folder_path, "tmp/backup"
12
12
  _cset :database_yml_path, 'config/database.yml'
13
13
  _cset :auto_migrate, true
14
+ _cset(:ssh) {"ssh -p #{fetch(:port, 22)} #{user}@#{serv}"}
14
15
 
15
16
  set :rvmrc_string ,"rvm use #{fetch(:ruby_version)}"
16
17
  after "deploy:update_code", "create:rvmrc"
@@ -1,6 +1,8 @@
1
1
  Capistrano::Configuration.instance(:must_exist).load do
2
2
  if exists?(:whenever) && fetch(:whenever) == true
3
3
  set :whenever_command, "bundle exec whenever"
4
+ set :whenever_environment, defer { stage }
5
+ set :whenever_identifier, defer { "#{application}_#{stage}" }
4
6
  require "whenever/capistrano/recipes"
5
7
  after "bundle:install", "whenever:update_crontab"
6
8
  after "deploy:rollback", "whenever:update_crontab"
@@ -1,3 +1,3 @@
1
1
  module Capobvious
2
- VERSION = "0.3.pre4"
2
+ VERSION = "0.3.pre5"
3
3
  end
metadata CHANGED
@@ -1,24 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capobvious
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.3.pre5
4
5
  prerelease: 4
5
- version: 0.3.pre4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dmitry Gruzd
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- type: :runtime
15
+ name: capistrano
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
+ type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
@@ -26,15 +27,15 @@ dependencies:
26
27
  - - ! '>='
27
28
  - !ruby/object:Gem::Version
28
29
  version: '0'
29
- name: capistrano
30
30
  - !ruby/object:Gem::Dependency
31
- type: :runtime
31
+ name: rvm-capistrano
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
+ type: :runtime
38
39
  prerelease: false
39
40
  version_requirements: !ruby/object:Gem::Requirement
40
41
  none: false
@@ -42,7 +43,6 @@ dependencies:
42
43
  - - ! '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
- name: rvm-capistrano
46
46
  description: Capfile that we use every day
47
47
  email:
48
48
  - donotsendhere@gmail.com
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: 1.3.1
94
94
  requirements: []
95
95
  rubyforge_project: capobvious
96
- rubygems_version: 1.8.24
96
+ rubygems_version: 1.8.25
97
97
  signing_key:
98
98
  specification_version: 3
99
99
  summary: Cap recipes