Skip to content
This repository
Browse code

Renamed the copy tasks to sync. Introduced the remote: namespace, to …

…separate restoration of remote/local assets. Updated the README and gemspec, upped the version to 0.1.2.
  • Loading branch information...
commit b32295431a7c7bee73ee9ab6858cf66cf250864e 1 parent 2896572
authored July 06, 2008
144  README
... ...
@@ -1,12 +1,15 @@
1  
-= capistrano-extensions
2  
-
  1
+= capistrano-extensions
  2
+
3 3
 * http://github.com/jtrupiano/capistrano-extensions
4 4
 
5 5
 == INCOMPLETE ==
6  
-* Missing a detailed sample config file
7  
-
8  
-== DESCRIPTION/FEATURES
9  
-
  6
+* Missing a detailed sample config file
  7
+* Describe the shortcomings (or rather my dissatisfaction) with the remote syncing executables for
  8
+  assets/db.  It works fine for now, but is a little wasteful.
  9
+* Database synchronization _only_ works for MySQL.
  10
+
  11
+== DESCRIPTION/FEATURES
  12
+
10 13
 This gem provides a base set of Capistrano extensions including the following:
11 14
   * a new :gemfile RemoteDependency type
12 15
   * tasks/helpers for handling public asset folders (e.g. created by the file_column plugin)
@@ -51,10 +54,10 @@ gems.  A separate ferret server may require it's own set of gems, etc.
51 54
   # Which directory does apache blindly load conf files from
52 55
   :apache_conf_dir --> /etc/apache2/sites-enabled
53 56
   
54  
-  # Full path to the graceful restart command of apache
  57
+  # Full path to the graceful restart command of apache
55 58
   :apache_restart_cmd --> /usr/sbin/apache2ctl
56 59
 
57  
-
  60
+
58 61
 == NEW RECIPES ==
59 62
 * deploy:create_shared_file_column_dirs
60 63
   
@@ -93,52 +96,93 @@ gems.  A separate ferret server may require it's own set of gems, etc.
93 96
 
94 97
   Restores the backed up content to the local development environment app
95 98
   
96  
-* local:copy_production_db
  99
+* local:sync_db
97 100
 
98 101
   Wrapper for local:backup_db and local:restore_db
99 102
   
100  
-* local:copy_production_content
  103
+* local:sync_content
101 104
 
102 105
   Wrapper for local:backup_content and local:restore_content
103 106
   
104  
-* local:copy_production
105  
-
106  
-  Wrapper for local:copy_production_db and local:copy_production_content
107  
-
108  
-== SYNOPSIS:
109  
-
110  
-  FIX (code sample of usage)
111  
-
112  
-== REQUIREMENTS:
113  
-
114  
-* Capistrano >= 2.3.0
115  
-
116  
-== INSTALL:
117  
-
  107
+* local:sync
  108
+
  109
+  Wrapper for local:sync_db and local:sync_content
  110
+
  111
+* remote:restore_db
  112
+
  113
+  Uploads the backup file downloaded from local:backup_db (specified via the FROM env variable), 
  114
+  copies it to the remove environment specified by RAILS_ENV, and imports (via mysql command line 
  115
+  tool) it back into the remote database.
  116
+
  117
+* remote:sync_db
  118
+
  119
+  Backs up target deployable environment's database (identified by the FROM environment variable, 
  120
+  which defaults to 'production') and restores it to the remote database identified by the TO 
  121
+  environment variable, which defaults to "staging."  
  122
+
  123
+  Because multiple capistrano configurations must be loaded, an external executable
  124
+  (capistrano-extensions-sync_db) is invoked, which independently calls capistrano.  See the 
  125
+  executable at $GEM_HOME/capistrano-extensions-0.1.2/bin/capistrano-extensions-sync_db
  126
+
  127
+  $> cap remote:sync_db FROM=production TO=staging
  128
+
  129
+* remote:restore_content
  130
+
  131
+  Uploads the backup file downloaded from local:backup_content (specified via the FROM env variable), 
  132
+  copies it to the remote environment specified by RAILS_ENV, and unpacks it into the shared/ 
  133
+  directory.
  134
+
  135
+* remote:sync_content
  136
+
  137
+  Backs up target deployable environment's shared content (identified by the FROM environment 
  138
+  variable, which defaults to 'production') and restores it to the remote environment identified 
  139
+  by the TO envrionment variable, which defaults to "staging."  
  140
+
  141
+  Because multiple capistrano configurations must be loaded, an external executable
  142
+  (capistrano-extensions-sync_content) is invoked, which independently calls capistrano.  See the 
  143
+  executable at $GEM_HOME/capistrano-extensions-0.1.2/bin/capistrano-extensions-sync_content
  144
+
  145
+  $> cap remote:sync_content FROM=production TO=staging
  146
+
  147
+* remote:sync
  148
+
  149
+  Wrapper for remote:sync_db and remote:sync_content.
  150
+
  151
+== SYNOPSIS:
  152
+
  153
+  FIX (code sample of usage)
  154
+
  155
+== REQUIREMENTS:
  156
+
  157
+* Capistrano = 2.4.3
  158
+* GemInstaller = 0.4.3
  159
+
  160
+== INSTALL:
  161
+
118 162
 * rake gem
119  
-* sudo gem install pkg/capistrano-extensions-0.1.0.gem --local
120  
-
121  
-== LICENSE:
122  
-
123  
-(The MIT License)
124  
-
125  
-Copyright (c) 2008 FIX
126  
-
127  
-Permission is hereby granted, free of charge, to any person obtaining
128  
-a copy of this software and associated documentation files (the
129  
-'Software'), to deal in the Software without restriction, including
130  
-without limitation the rights to use, copy, modify, merge, publish,
131  
-distribute, sublicense, and/or sell copies of the Software, and to
132  
-permit persons to whom the Software is furnished to do so, subject to
133  
-the following conditions:
134  
-
135  
-The above copyright notice and this permission notice shall be
136  
-included in all copies or substantial portions of the Software.
137  
-
138  
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
139  
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
140  
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
141  
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
142  
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
143  
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
144  
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  163
+* sudo gem install pkg/capistrano-extensions-0.1.2.gem --local
  164
+
  165
+== LICENSE:
  166
+
  167
+(The MIT License)
  168
+
  169
+Copyright (c) 2008 FIX
  170
+
  171
+Permission is hereby granted, free of charge, to any person obtaining
  172
+a copy of this software and associated documentation files (the
  173
+'Software'), to deal in the Software without restriction, including
  174
+without limitation the rights to use, copy, modify, merge, publish,
  175
+distribute, sublicense, and/or sell copies of the Software, and to
  176
+permit persons to whom the Software is furnished to do so, subject to
  177
+the following conditions:
  178
+
  179
+The above copyright notice and this permission notice shall be
  180
+included in all copies or substantial portions of the Software.
  181
+
  182
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  183
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  184
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  185
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  186
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  187
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  188
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9  bin/capistrano-extensions-sync-content
... ...
@@ -0,0 +1,9 @@
  1
+#!/usr/bin/env ruby
  2
+
  3
+if ARGV.size < 2
  4
+  puts "Improper invocation: capistrano-extensions-copy-production-db backup_env restore_env"
  5
+  exit 1
  6
+end
  7
+
  8
+system("cap local:backup_content RAILS_ENV=#{ARGV[0]}")
  9
+system("cap remote:restore_content RAILS_ENV=#{ARGV[1]} FROM=#{ARGV[0]}")
2  bin/capistrano-extensions-copy-production-db → bin/capistrano-extensions-sync-db
@@ -6,4 +6,4 @@ if ARGV.size < 2
6 6
 end
7 7
 
8 8
 system("cap local:backup_db RAILS_ENV=#{ARGV[0]}")
9  
-system("cap local:restore_db RAILS_ENV=#{ARGV[1]} FROM=#{ARGV[0]}")
  9
+system("cap remote:restore_db RAILS_ENV=#{ARGV[1]} FROM=#{ARGV[0]}")
12  capistrano-extensions.gemspec
... ...
@@ -1,17 +1,17 @@
1 1
 Gem::Specification.new do |s|
2 2
   s.name = "capistrano-extensions"
3  
-  s.version = PKG_VERSION
  3
+  s.version = PKG_VERSION
4 4
   s.platform = Gem::Platform::RUBY
5  
-  s.author = "John Trupiano"
  5
+  s.author = "John Trupiano"
6 6
   s.email = "jtrupiano@gmail.com"
7 7
   s.description = %q(A base set of Capistrano extensions-- aids with the file_column plugin, the GemInstaller gem, multiple deployable environments, logfile helpers, and database/asset synchronization from production to local environment)
8 8
   s.summary = s.description # More details later??
9 9
   s.has_rdoc = false
10 10
   s.require_paths = ["lib"]
11 11
   
12  
-  s.files = Dir.glob("{lib}/**/*") + Dir['bin/*'] + %w(README)
13  
-  s.executables = ['capistrano-extensions-copy-production-db']
  12
+  s.files = Dir.glob("{lib}/**/*") + Dir['bin/*'] + %w(README)
  13
+  s.executables = %w(capistrano-extensions-sync-db capistrano-extensions-sync-content)
14 14
   
15  
-  s.add_dependency(%q<capistrano>, ["= 2.4.3"])
16  
-  s.add_dependency(%q<geminstaller>, ['= 0.4.2'])
  15
+  s.add_dependency(%q<capistrano>, ["= 2.4.3"])
  16
+  s.add_dependency(%q<geminstaller>, ['= 0.4.3'])
17 17
 end
386  lib/capistrano-extensions/deploy.rb
@@ -3,45 +3,45 @@
3 3
 
4 4
 # Overrides the majority of recipes from Capistrano's deploy recipe set.
5 5
 Capistrano::Configuration.instance(:must_exist).load do
6  
-  # Add sls_recipes to the load path  
  6
+  # Add sls_recipes to the load path  
7 7
   @load_paths << File.expand_path(File.dirname(__FILE__))
8  
-
9  
-  # ========================================================================
10  
-  # These variables MUST be set in the client capfiles. If they are not set,
11  
-  # the deploy will fail with an error.
12  
-  # ========================================================================
13  
-
14 8
 
15  
-  # =========================================================================
16  
-  # These variables may be set in the client capfile if their default values
17  
-  # are not sufficient.
18  
-  # =========================================================================
19  
-
20  
-  _cset(:content_directories, [])
21  
-  _cset(:rails_env) { ENV['RAILS_ENV'].nil? ? fetch(:deployable_environments).first : ENV['RAILS_ENV'] }  
22  
-
23  
-  # =========================================================================
24  
-  # These variables should NOT be changed unless you are very confident in
25  
-  # what you are doing. Make sure you understand all the implications of your
26  
-  # changes if you do decide to muck with these!
27  
-  # =========================================================================
  9
+  # ========================================================================
  10
+  # These variables MUST be set in the client capfiles. If they are not set,
  11
+  # the deploy will fail with an error.
  12
+  # ========================================================================
28 13
 
29  
-  set(:use_sudo, false)     # we don't want to use sudo-- we don't have to!
30  
-  set(:deploy_via, :export) # we don't want our .svn folders on the server!
  14
+
  15
+  # =========================================================================
  16
+  # These variables may be set in the client capfile if their default values
  17
+  # are not sufficient.
  18
+  # =========================================================================
  19
+
  20
+  _cset(:content_directories, [])
  21
+  _cset(:rails_env) { ENV['RAILS_ENV'].nil? ? fetch(:deployable_environments).first : ENV['RAILS_ENV'] }  
  22
+
  23
+  # =========================================================================
  24
+  # These variables should NOT be changed unless you are very confident in
  25
+  # what you are doing. Make sure you understand all the implications of your
  26
+  # changes if you do decide to muck with these!
  27
+  # =========================================================================
  28
+
  29
+  set(:use_sudo, false)     # we don't want to use sudo-- we don't have to!
  30
+  set(:deploy_via, :export) # we don't want our .svn folders on the server!
31 31
   _cset(:deploy_to) { "/var/www/vhosts/#{application}" }
32  
-  _cset(:deployable_environments, [:production])
33  
-
34  
-  _cset(:rails_config_path) { File.join(latest_release, 'config') }
  32
+  _cset(:deployable_environments, [:production])
  33
+
  34
+  _cset(:rails_config_path) { File.join(latest_release, 'config') }
35 35
   _cset(:db_conf)           { 
36 36
     fetch(:config_structure, :rails).to_sym == :sls ?
37 37
       File.join(rails_config_path, rails_env, 'database.yml') :
38 38
       File.join(rails_config_path, 'database.yml')
39  
-  }
40  
-
41  
-  # Where uploaded content is stored
42  
-  _cset(:content_dir, "content")
43  
-  _cset(:content_path)  { File.join(shared_path, content_dir) }
44  
-  _cset(:public_path)   { File.join(latest_release, 'public') }
  39
+  }
  40
+
  41
+  # Where uploaded content is stored
  42
+  _cset(:content_dir, "content")
  43
+  _cset(:content_path)  { File.join(shared_path, content_dir) }
  44
+  _cset(:public_path)   { File.join(latest_release, 'public') }
45 45
   _cset(:log_path)      { "/var/log/#{application}" }
46 46
   
47 47
   # Allow recipes to ask for a certain local environment
@@ -50,14 +50,11 @@ def local_db_conf(env = nil)
50 50
     fetch(:config_structure, :rails).to_sym == :sls ?
51 51
       File.join('config', env, 'database.yml') :
52 52
       File.join('config', 'database.yml')
53  
-  end
54  
-
55  
-  # Read from the local machine-- BE CAREFUL!!!
  53
+  end
  54
+
  55
+  # Read from the local machine-- BE CAREFUL!!!
56 56
   set(:db) { YAML.load_file(local_db_conf)[rails_env] }
57 57
 
58  
-  # HOLDS REFERENCES TO EACH OF THE DEPLOYABLE ENVIRONMENT BLOCKS
59  
-  @env_procs = {}
60  
-      
61 58
   # Let's define helpers for our deployable environments
62 59
   # Can we possibly just infer this from the config directory structure?
63 60
   deployable_environments.each do |env|
@@ -65,218 +62,219 @@ def local_db_conf(env = nil)
65 62
       def #{env.to_s}(&block)
66 63
         if rails_env.to_s == '#{env.to_s}'
67 64
           puts "*** Deploying to the \033[1;41m  #{env.to_s.capitalize} \033[0m server!"
  65
+          yield
68 66
           puts <<-DEBUG
69  
-            rails_env: \#{rails_env}
70  
-            deploy_to: \#{deploy_to}
  67
+            rails_env: \#{rails_env}
  68
+            deploy_to: \#{deploy_to}
71 69
             content_directories: \#{content_directories.join(', ')}
72 70
           DEBUG
73  
-          block.call if block_given?
74  
-          @env_procs[:#{env}] = block
75 71
         end
76 72
       end
77 73
     CODE
78 74
     eval src
79 75
   end
80 76
 
81  
-
82  
-  # all deployable environments get a pseudo-namespaced role
83  
-  # as (e.g.) app_staging, app_production, web_staging, etc.
84  
-  #temp = {}
85  
-  #deployable_environments.each do |env|
86  
-  #  find_and_execute_task(env)
87  
-  #  roles.each { |name, role| temp[:"#{name}_#{env}"] = role }
88  
-  #  roles.clear    
89  
-  #end
90  
-  #temp.each { |name, role| roles[name] = role }
91  
-
92  
-  # return the set of roles specific to an environment
93  
-  #def roles_for(env)
94  
-  #  roles.reject { |name, role| name =~ Regexp.new("/_#{env}$/") }
95  
-  #end
96  
-
97  
-
98  
-  # Helper function to allow you to temporarily change the deployment environment
99  
-  # Useful for when you need to deal with several deployable environments
100  
-  def change_deploy_env(new_env)
101  
-      # convert the current deploy environment to new_env
102  
-      old_rails_env = rails_env
103  
-
104  
-      set(rails_env, new_env)
105  
-      roles.clear
106  
-      @env_procs[rails_env.to_sym].call
107  
-
108  
-      server = Capistrano::ServerDefinition.new(ip, :user => user, :password => password) #@configuration.find_servers
109  
-      establish_connections_to([server])
110  
-
111  
-      execute_on_servers do
112  
-        yield
113  
-      end      
114  
-
115  
-  ensure
116  
-      # Set the environment back!
117  
-      set(rails_env, old_rails_env)
118  
-      roles.clear
119  
-      @env_procs[rails_env.to_sym].call
120  
-
121  
-      server = Capistrano::ServerDefinition.new(ip) #@configuration.find_servers
122  
-      establish_connections_to([server])
123  
-  end
124  
-
125 77
   # Now, let's actually include our common recipes!
126 78
   namespace :deploy do
127  
-    desc <<-DESC
  79
+    desc <<-DESC
128 80
       [capistrano-extensions] Creates shared filecolumn directories and symbolic links to them by 
129 81
       reading the :content_directories property.  Note that this task is not invoked by default,
130 82
       but rather is exposed to you as a helper.  To utilize, you'll want to override
131  
-      deploy:default and invoke this yourself.
132  
-    DESC
133  
-    task :create_shared_file_column_dirs, :roles => :app, :except => { :no_release => true } do
134  
-      content_directories.each do |fc|
135  
-        run <<-CMD
136  
-          mkdir -p #{content_path}/#{fc} && 
137  
-          ln -sf #{content_path}/#{fc} #{public_path}/#{fc} &&
138  
-          chmod 775 -R #{content_path}/#{fc}
139  
-        CMD
140  
-      end
  83
+      deploy:default and invoke this yourself.
  84
+    DESC
  85
+    task :create_shared_file_column_dirs, :roles => :app, :except => { :no_release => true } do
  86
+      content_directories.each do |fc|
  87
+        run <<-CMD
  88
+          mkdir -p #{content_path}/#{fc} && 
  89
+          ln -sf #{content_path}/#{fc} #{public_path}/#{fc} &&
  90
+          chmod 775 -R #{content_path}/#{fc}
  91
+        CMD
  92
+      end
141 93
     end
142 94
     
143  
-    desc <<-DESC
  95
+    desc <<-DESC
144 96
       [capistrano-extensions]: Invokes geminstaller to ensure that the proper gem set is installed on 
145 97
       the target server.  Note that this task is not invoked by default, but rather is exposed to you
146  
-      as a helper.
147  
-    DESC
148  
-    task :gem_update, :roles => :app do
149  
-      run <<-CMD
150  
-        gem sources -u &&
151  
-        sudo geminstaller -e -c #{rails_config_path}/geminstaller.yml
152  
-      CMD
153  
-    end
154  
-
  98
+      as a helper.
  99
+    DESC
  100
+    task :gem_update, :roles => :app do
  101
+      run <<-CMD
  102
+        gem sources -u &&
  103
+        #{sudo} geminstaller -e -c #{rails_config_path}/geminstaller.yml
  104
+      CMD
  105
+    end
  106
+
155 107
   end
156 108
   
157  
-  namespace :log do
  109
+  namespace :log do
158 110
     desc <<-DESC
159 111
       [capistrano-extensions]: Tarballs deployable environment's rails logfile (identified by 
160 112
       RAILS_ENV environment variable, which defaults to 'production') and copies it to the local
161 113
       filesystem
162  
-    DESC
  114
+    DESC
163 115
     task :pull do
164 116
       tmp_location = "#{shared_path}/#{rails_env}.log.gz"
165  
-      run "cp #{log_path}/#{rails_env}.log #{shared_path}/ && gzip #{shared_path}/#{rails_env}.log"
166  
-      get "#{tmp_location}", "#{application}-#{rails_env}.log.gz"
167  
-      run "rm #{tmp_location}"
168  
-    end
  117
+      run "cp #{log_path}/#{rails_env}.log #{shared_path}/ && gzip #{shared_path}/#{rails_env}.log"
  118
+      get "#{tmp_location}", "#{application}-#{rails_env}.log.gz"
  119
+      run "rm #{tmp_location}"
  120
+    end
169 121
   end
170 122
 
171 123
   namespace :remote do
172  
-    desc <<-DESC
  124
+    desc <<-DESC
173 125
       [capistrano-extensions] Uploads the backup file downloaded from local:backup_db (specified via the FROM env variable), 
174 126
       copies it to the remove environment specified by RAILS_ENV, and imports (via mysql command line tool) it back into the 
175  
-      remote database.
176  
-    DESC
177  
-    task :restore_db, :roles => :db do
178  
-      env = ENV['FROM'] || 'production'
  127
+      remote database.
  128
+    DESC
  129
+    task :restore_db, :roles => :db do
  130
+      env = ENV['FROM'] || 'production'
179 131
       
180 132
       puts "\033[1;41m Restoring database backup to #{rails_env} environment \033[0m"
181 133
       if deployable_environments.include?(rails_env.to_sym)
182 134
         # remote environment
183  
-        local_backup_file = "#{application}-#{env}-db.sql.gz}"
184  
-        upload(local_backup_file, "#{shared_path}/restore_db.sql.gz")
185  
-        #run "gunzip #{shared_path}/restore_db.sql.gz"
186  
-        #run "mysql -u #{user} --password=#{pass} #{db} < #{shared_path/restore_db.sql}"
187  
-        #run "rm -f #{shared_path}/restore_db.sql #{shared_path}/restore_db.sql.gz"
188  
-      end
  135
+        local_backup_file = "#{application}-#{env}-db.sql.gz"
  136
+        remote_file       = "#{shared_path}/restore_db.sql"
  137
+        if !File.exists?(local_backup_file)
  138
+          puts "Could not find backup file: #{local_backup_file}"
  139
+          exit 1
  140
+        end
  141
+        upload(local_backup_file, "#{remote_file}.gz")
  142
+        run "gunzip -f #{remote_file}.gz"
  143
+        run "mysql -u #{db['username']} --password=#{db['password']} #{db['database']} < #{remote_file}"
  144
+        run "rm -f #{remote_file}"
  145
+      end
189 146
     end
190 147
 
191  
-    desc <<-DESC
  148
+    desc <<-DESC
192 149
       [capistrano-extensions]: Backs up target deployable environment's database (identified
193 150
       by the FROM environment variable, which defaults to 'production') and restores it to 
194  
-      the remote database identified by the TO environment variable, which defaults to "staging"
195  
-    DESC
196  
-    task :copy_production_db do
197  
-      local::backup_db
198  
-      system("capistrano-extensions-copy-production-db #{ENV['FROM'] || 'production'||} #{ENV['TO'] || 'staging'}")
  151
+      the remote database identified by the TO environment variable, which defaults to "staging."
  152
+    DESC
  153
+    task :sync_db do
  154
+      system("capistrano-extensions-sync-db #{ENV['FROM'] || 'production'} #{ENV['TO'] || 'staging'}")
  155
+    end
  156
+
  157
+    desc <<-DESC
  158
+      [capistrano-extensions]: Uploads the backup file downloaded from local:backup_content (specified via the 
  159
+      FROM env variable), copies it to the remote environment specified by RAILS_ENV, and unpacks it into the 
  160
+      shared/ directory.
  161
+    DESC
  162
+    task :restore_content do
  163
+      from = ENV['FROM'] || 'production'
  164
+      
  165
+      if deployable_environments.include?(rails_env.to_sym)
  166
+        local_backup_file = "#{application}-#{from}-content_backup.tar.gz"
  167
+        remote_file       = "#{content_path}/content_backup.tar.gz"
  168
+        
  169
+        if !File.exists?(local_backup_file)
  170
+          puts "Could not find backup file: #{local_backup_file}"
  171
+          exit 1
  172
+        end
  173
+        
  174
+        upload(local_backup_file, "#{remote_file}")
  175
+        run("tar xzf #{remote_file} -C #{content_path}/")
  176
+        run("rm -f #{remote_file}")
  177
+      end
  178
+    end
  179
+    
  180
+    desc <<-DESC
  181
+      [capistrano-extensions]: Backs up target deployable environment's shared content (identified
  182
+      by the FROM environment variable, which defaults to 'production') and restores it to the
  183
+      remote environment identified by the TO envrionment variable, which defaults to "staging."
  184
+    DESC
  185
+    task :sync_content do
  186
+      system("capistrano-extensions-sync-content #{ENV['FROM'] || 'production'} #{ENV['TO'] || 'staging'}")
  187
+    end
  188
+    
  189
+    desc <<-DESC
  190
+      Wrapper fro remote:sync_db and remote:sync_content.
  191
+    DESC
  192
+    task :sync do
  193
+      sync_db
  194
+      sync_content
199 195
     end
200  
-  end
201  
-
202  
-  namespace :local do
203  
-    desc <<-DESC
  196
+  end
  197
+
  198
+  namespace :local do
  199
+    desc <<-DESC
204 200
       [capistrano-extensions]: Backs up deployable environment's database (identified by the 
205  
-      RAILS_ENV environment variable, which defaults to 'production') and copies it to the local machine
206  
-    DESC
207  
-    task :backup_db, :roles => :db do 
208  
-      run "mysqldump --user=#{db['username']} --password=#{db['password']} #{db['database']} > #{shared_path}/db_backup.sql"
209  
-      run "gzip #{shared_path}/db_backup.sql"
210  
-      get "#{shared_path}/db_backup.sql.gz", "#{application}-#{rails_env}-db.sql.gz"
211  
-      run "rm -f #{shared_path}/db_backup.sql.gz"
212  
-    end
213  
-    
214  
-    desc <<-DESC
  201
+      RAILS_ENV environment variable, which defaults to 'production') and copies it to the local machine
  202
+    DESC
  203
+    task :backup_db, :roles => :db do 
  204
+      run "mysqldump --user=#{db['username']} --password=#{db['password']} #{db['database']} > #{shared_path}/db_backup.sql"
  205
+      run "gzip #{shared_path}/db_backup.sql"
  206
+      get "#{shared_path}/db_backup.sql.gz", "#{application}-#{rails_env}-db.sql.gz"
  207
+      run "rm -f #{shared_path}/db_backup.sql.gz #{shared_path}/db_backup.sql"
  208
+    end
  209
+    
  210
+    desc <<-DESC
215 211
       [capistrano-extensions] Untars the backup file downloaded from local:backup_db (specified via the FROM env variable), 
216 212
       and imports (via mysql command line tool) it back into the database defined in the RAILS_ENV env variable.  
217 213
       Support now exists for RAILS_ENV to be a remote server.  You must first ensure that :deployable_environments has this environment.
218  
-      RAILS_ENV defaults to development.
219  
-    DESC
220  
-    task :restore_db, :roles => :db do
221  
-      env = ENV['FROM'] || 'production'
  214
+      RAILS_ENV defaults to development.
  215
+    DESC
  216
+    task :restore_db, :roles => :db do
  217
+      from = ENV['FROM'] || 'production'
222 218
       
223 219
       env = ENV['RESTORE_ENV'] || 'development'
224 220
       y = YAML.load_file(local_db_conf(env))[env]
225 221
       db, user, pass = y['database'], y['username'], y['password'] # update me!
226 222
 
227  
-      puts "\033[1;41m Restoring database backup to #{rails_env} environment \033[0m"
228  
-      # local
229  
-      system "gunzip #{application}-#{rails_env}-db.sql.gz"
230  
-      system "mysql -u #{user} --password=#{pass} #{db} < #{application}-#{rails_env}-db.sql"
231  
-      system "rm -f #{application}-#{rails_env}-db.sql"
232  
-    end
233  
-    
234  
-    desc <<-DESC
  223
+      puts "\033[1;41m Restoring database backup to #{env} environment \033[0m"
  224
+      # local
  225
+      system "gunzip #{application}-#{from}-db.sql.gz"
  226
+      system "mysql -u #{user} -p#{pass} #{db} < #{application}-#{from}-db.sql"
  227
+      system "rm -f #{application}-#{from}-db.sql"
  228
+    end
  229
+    
  230
+    desc <<-DESC
235 231
       [capistrano-extensions]: Downloads a tarball of uploaded content (that lives in public/ 
236 232
       directory, as specified by the :content_directories property) from the production site 
237  
-      back to the local filesystem
238  
-    DESC
239  
-    task :backup_content do
240  
-      run "cd #{content_path} && tar czf #{shared_path}/content_backup.tar.gz *"
241  
-      get "#{shared_path}/content_backup.tar.gz", "#{application}-#{rails_env}-content_backup.tar.gz"
242  
-      run "rm -f #{shared_path}/content_backup.tar.gz"
243  
-    end
244  
-    
245  
-    desc <<-DESC
246  
-      [capistrano-extensions]: Restores the backed up content to the local development environment app
247  
-    DESC
248  
-    task :restore_content do
249  
-      system "tar xzf #{application}-#{rails_env}-content_backup.tar.gz -C public/"
250  
-      system "rm -f #{application}-#{rails_env}-content_backup.tar.gz"
251  
-    end
252  
-    
253  
-    desc <<-DESC
  233
+      back to the local filesystem
  234
+    DESC
  235
+    task :backup_content do
  236
+      run "cd #{content_path} && tar czf #{shared_path}/content_backup.tar.gz *"
  237
+      get "#{shared_path}/content_backup.tar.gz", "#{application}-#{rails_env}-content_backup.tar.gz"
  238
+      run "rm -f #{shared_path}/content_backup.tar.gz"
  239
+    end
  240
+    
  241
+    desc <<-DESC
  242
+      [capistrano-extensions]: Restores the backed up content to the local development environment app
  243
+    DESC
  244
+    task :restore_content do
  245
+      from = ENV['FROM'] || 'production'
  246
+      
  247
+      system "tar xzf #{application}-#{from}-content_backup.tar.gz -C public/"
  248
+      system "rm -f #{application}-#{from}-content_backup.tar.gz"
  249
+    end
  250
+    
  251
+    desc <<-DESC
254 252
       [capistrano-extensions]: Backs up target deployable environment's database (identified
255 253
       by the RAILS_ENV environment variable, which defaults to 'production') and restores it to 
256  
-      the local database identified by the RESTORE_ENV environment variable, which defaults to "development"
257  
-    DESC
258  
-    task :copy_production_db do
259  
-      backup_db
  254
+      the local database identified by the RESTORE_ENV environment variable, which defaults to "development"
  255
+    DESC
  256
+    task :sync_db do
  257
+      backup_db
260 258
       restore_db
261  
-    end
262  
-    
263  
-    desc <<-DESC
  259
+    end
  260
+    
  261
+    desc <<-DESC
264 262
       [capistrano-extensions]: Backs up the target deployable environment's content directories (identified
265  
-      by the RAILS_ENV environment variable, which defaults to 'production') and restores them to the
266  
-      local development filesystem
267  
-    DESC
268  
-    task :copy_production_content do
269  
-      backup_content
270  
-      restore_content
271  
-    end
272  
-    
273  
-    desc <<-DESC
  263
+      by the RAILS_ENV environment variable, which defaults to 'production') and restores them to the
  264
+      local development filesystem
  265
+    DESC
  266
+    task :sync_content do
  267
+      backup_content
  268
+      restore_content
  269
+    end
  270
+    
  271
+    desc <<-DESC
274 272
       [capistrano-extensions]: Copies all target (production or staging) data and content to a local environment
275  
-      identified by the RESTORE_ENV environment variable, which defaults to "development"
276  
-    DESC
277  
-    task :copy_production do
278  
-      copy_production_db
279  
-      copy_production_content
280  
-    end
  273
+      identified by the RESTORE_ENV environment variable, which defaults to "development"
  274
+    DESC
  275
+    task :sync do
  276
+      copy_production_db
  277
+      copy_production_content
  278
+    end
281 279
   end
282 280
 end
2  lib/capistrano-extensions/version.rb
@@ -12,7 +12,7 @@ def self.check(required, actual) #:nodoc:
12 12
 
13 13
     MAJOR = 0
14 14
     MINOR = 1
15  
-    TINY  = 1
  15
+    TINY  = 2
16 16
 
17 17
     STRING = [MAJOR, MINOR, TINY].join(".")
18 18
   end

0 notes on commit b322954

Please sign in to comment.
Something went wrong with that request. Please try again.