lib/capones_recipes/tasks/database/sync.rb in capones_recipes-1.1.0 vs lib/capones_recipes/tasks/database/sync.rb in capones_recipes-1.1.1

- old
+ new

@@ -62,16 +62,17 @@ # Download dump download "#{shared_path}/sync/#{filename}", filename # Local DB import username, password, database, host = database_config('development') - system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}" + run "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}" + run "rm -f #{filename}" logger.important "sync database from the stage '#{stage}' to local finished" # Start db:migrate - system "rake db:migrate" + run "rake db:migrate" end desc <<-DESC Sync declared directories from the selected multi_stage environment to the local development environment. The synced directories must be declared as an array of Strings with the sync_directories @@ -88,11 +89,11 @@ logger.info "create local '#{syncdir}' folder" Dir.mkdir "#{syncdir}" end logger.info "sync #{syncdir} from #{server}:#{port} to local" destination, base = Pathname.new(syncdir).split - system "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{current_path}/#{syncdir} #{destination.to_s}" + run "rsync --verbose --archive --compress --copy-links --delete --stats --rsh='ssh -p #{port}' #{user}@#{server}:#{current_path}/#{syncdir} #{destination.to_s}" end logger.important "sync filesystem from the stage '#{stage}' to local finished" end @@ -131,11 +132,12 @@ # Download dump download "#{shared_path}/sync/#{filename}", filename # Local DB import username, password, database, host = database_config('development') - system "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}; rm -f #{filename}" + run "bzip2 -d -c #{filename} | mysql -u #{username} --password='#{password}' #{database}" + run "rm -f #{filename}" logger.important "sync database from the stage '#{stage}' to local finished" end end end @@ -177,18 +179,19 @@ # Local DB export filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2" username, password, database, host = database_config('development') host_option = host ? "--host='#{host}'" : "" - system "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}" + run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}" upload filename, "#{shared_path}/sync/#{filename}" system "rm -f #{filename}" # Remote DB import username, password, database, host = remote_database_config(stage) host_option = host ? "--host='#{host}'" : "" - run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}; rm -f #{shared_path}/sync/#{filename}" + run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}" + run "rm -f #{shared_path}/sync/#{filename}" purge_old_backups "database.all" logger.important "sync database from local to the stage '#{stage}' finished" end @@ -214,11 +217,11 @@ run "mkdir #{current_path}/#{syncdir}" end # Sync directory up logger.info "sync #{syncdir} to #{server}:#{port} from local" - system "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{current_path}/#{destination.to_s}" + run "rsync --verbose --archive --compress --keep-dirlinks --delete --stats --rsh='ssh -p #{port}' #{syncdir} #{user}@#{server}:#{current_path}/#{destination.to_s}" end logger.important "sync filesystem from local to the stage '#{stage}' finished" end namespace :kuhsaft do @@ -257,17 +260,18 @@ # Local DB export filename = "dump.local.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2" username, password, database, host = database_config('development') host_option = host ? "--host='#{host}'" : "" - system "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}" + run "mysqldump -u #{username} --password='#{password}' #{host_option} #{database} | bzip2 -9 > #{filename}" upload filename, "#{shared_path}/sync/#{filename}" system "rm -f #{filename}" # Remote DB import username, password, database, host = remote_database_config(stage) host_option = host ? "--host='#{host}'" : "" - run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}; rm -f #{shared_path}/sync/#{filename}" + run "bzip2 -d -c #{shared_path}/sync/#{filename} | mysql -u #{username} --password='#{password}' #{host_option} #{database}" + run "rm -f #{shared_path}/sync/#{filename}" purge_old_backups "database.kuhsaft" logger.important "sync database from local to the stage '#{stage}' finished" end end