From 512d77d662aefd9e114cae48c727aaa874344120 Mon Sep 17 00:00:00 2001 From: Evan Kaufman Date: Fri, 19 Jun 2015 12:34:51 -0500 Subject: [PATCH 1/2] Updated rsync options on `up:files` to match `down:files` * added `--delete` to remove files on destination that don't exist on source * added `--copy-links` to copy _content_ of symlinks as files, rather than preserving links * removed `--keep-dirlinks` to preserve symlink directories as links This is a **potentially breaking change** --- deployment/lib/sync.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/lib/sync.rb b/deployment/lib/sync.rb index 2aae851..c797527 100644 --- a/deployment/lib/sync.rb +++ b/deployment/lib/sync.rb @@ -121,7 +121,7 @@ find_servers_for_task(current_task).each do |current_server| system "chmod 600 #{ssh_options[:keys][0]}" unless ssh_options.keys.empty? - system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --keep-dirlinks #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/ #{user}@#{current_server}:#{remote_web}/" + system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --delete --copy-links #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/ #{user}@#{current_server}:#{remote_web}/" end end @@ -132,7 +132,7 @@ find_servers_for_task(current_task).each do |current_server| system "chmod 600 #{ssh_options[:keys][0]}" unless ssh_options.keys.empty? rsync_limited.each do |key| - system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --keep-dirlinks #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/#{key}/ #{user}@#{current_server}:#{remote_web}/#{key}/" + system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --delete --copy-links #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/#{key}/ #{user}@#{current_server}:#{remote_web}/#{key}/" end end end From d3cb1eb6bd8f350d84ff1544ebacdb6ad54c6c50 Mon Sep 17 00:00:00 2001 From: Evan Kaufman Date: Thu, 25 Jun 2015 17:48:04 -0500 Subject: [PATCH 2/2] Moved destructive sync to genesis:up:mirror --- deployment/lib/sync.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/deployment/lib/sync.rb b/deployment/lib/sync.rb index c797527..4848ba6 100644 --- a/deployment/lib/sync.rb +++ b/deployment/lib/sync.rb @@ -44,6 +44,28 @@ end end +before "genesis:up:mirror" do + set(:confirmed) do + logger.important <<-WARN + + ======================================================== + + WARNING: You are about to DESTRUCTIVELY override "#{stage}" files! + + ======================================================== + + WARN + + answer = Capistrano::CLI.ui.ask " Are you sure you want to continue? (YES) " + if answer === 'YES' then true else false end + end + + unless fetch(:confirmed) + logger.info "\Aborted!" + exit + end +end + namespace :genesis do namespace :down do desc "Downloads both remote database & syncs remote files into Vagrant" @@ -119,6 +141,16 @@ task :files, :roles => :web do set :excludes, "--exclude '#{rsync_exclude.join('\' --exclude \'')}'" + find_servers_for_task(current_task).each do |current_server| + system "chmod 600 #{ssh_options[:keys][0]}" unless ssh_options.keys.empty? + system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --keep-dirlinks #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/ #{user}@#{current_server}:#{remote_web}/" + end + end + + desc "Destructively syncs local project files to remote" + task :mirror, :roles => :web do + set :excludes, "--exclude '#{rsync_exclude.join('\' --exclude \'')}'" + find_servers_for_task(current_task).each do |current_server| system "chmod 600 #{ssh_options[:keys][0]}" unless ssh_options.keys.empty? system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --delete --copy-links #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/ #{user}@#{current_server}:#{remote_web}/" @@ -132,7 +164,7 @@ find_servers_for_task(current_task).each do |current_server| system "chmod 600 #{ssh_options[:keys][0]}" unless ssh_options.keys.empty? rsync_limited.each do |key| - system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --delete --copy-links #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/#{key}/ #{user}@#{current_server}:#{remote_web}/#{key}/" + system "rsync -e \"ssh -i #{ssh_options[:keys][0]}\" -avvru --keep-dirlinks #{excludes} --progress #{'--dry-run' if dry_run} #{local_web}/#{key}/ #{user}@#{current_server}:#{remote_web}/#{key}/" end end end