Permalink
Browse files

replace run block for data capturing with capture method + make try_s…

…udo work

- replaced the run blocks for data capturing with the capture method
- used sh -c around the try_sudo commands to make the the whole command
run by the sudo user and not only the part before the |
- used force delete to skip the 'remove write-protected regular file?'
question
  • Loading branch information...
1 parent c38d92a commit dce62e39c3cfe8b2954213e91c57c3fe556a9c41 @daanporon daanporon committed Feb 16, 2013
Showing with 15 additions and 21 deletions.
  1. +15 −21 lib/symfony2/database.rb
@@ -11,19 +11,16 @@
sqlfile = "#{application}_dump.sql"
config = ""
- run "#{try_sudo} cat #{current_path}/#{app_config_path}/#{app_config_file}" do |ch, st, data|
- config = load_database_config data, symfony_env_prod
- end
+ data = capture("#{try_sudo} cat #{current_path}/#{app_config_path}/#{app_config_file}")
+ config = load_database_config data, symfony_env_prod
case config['database_driver']
when "pdo_mysql", "mysql"
- run "#{try_sudo} mysqldump -u#{config['database_user']} --host='#{config['database_host']}' --password='#{config['database_password']}' #{config['database_name']} | gzip -c > #{file}" do |ch, stream, data|
- puts data
- end
+ data = capture("#{try_sudo} sh -c 'mysqldump -u#{config['database_user']} --host='#{config['database_host']}' --password='#{config['database_password']}' #{config['database_name']} | gzip -c > #{file}'")
+ puts data
when "pdo_pgsql", "pgsql"
- run "#{try_sudo} pg_dump -U #{config['database_user']} #{config['database_name']} --clean | gzip -c > #{file}" do |ch, stream, data|
- puts data
- end
+ data = capture("#{try_sudo} sh -c 'pg_dump -U #{config['database_user']} #{config['database_name']} --clean | gzip -c > #{file}'")
+ puts data
end
FileUtils.mkdir_p("backups")
@@ -33,7 +30,7 @@
rescue Exception # fallback for file systems that don't support symlinks
FileUtils.cp_r("backups/#{filename}", "backups/#{application}.#{env}_dump.latest.sql.gz")
end
- run "#{try_sudo} rm #{file}"
+ run "#{try_sudo} rm -f #{file}"
end
desc "Dumps local database"
@@ -106,23 +103,20 @@
upload(file, "#{remote_tmp_dir}/#{filename}", :via => :scp)
run "#{try_sudo} gunzip -c #{remote_tmp_dir}/#{filename} > #{remote_tmp_dir}/#{sqlfile}"
- run "#{try_sudo} cat #{current_path}/#{app_config_path}/#{app_config_file}" do |ch, st, data|
- config = load_database_config data, symfony_env_prod
- end
+ data = capture("#{try_sudo} cat #{current_path}/#{app_config_path}/#{app_config_file}")
+ config = load_database_config data, symfony_env_prod
case config['database_driver']
when "pdo_mysql", "mysql"
- run "#{try_sudo} mysql -u#{config['database_user']} --host='#{config['database_host']}' --password='#{config['database_password']}' #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}" do |ch, stream, data|
- puts data
- end
+ data = capture("#{try_sudo} mysql -u#{config['database_user']} --host='#{config['database_host']}' --password='#{config['database_password']}' #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}")
+ puts data
when "pdo_pgsql", "pgsql"
- run "#{try_sudo} psql -U #{config['database_user']} #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}" do |ch, stream, data|
- puts data
- end
+ data = capture("#{try_sudo} psql -U #{config['database_user']} #{config['database_name']} < #{remote_tmp_dir}/#{sqlfile}")
+ puts data
end
- run "#{try_sudo} rm #{remote_tmp_dir}/#{filename}"
- run "#{try_sudo} rm #{remote_tmp_dir}/#{sqlfile}"
+ run "#{try_sudo} rm -f #{remote_tmp_dir}/#{filename}"
+ run "#{try_sudo} rm -f #{remote_tmp_dir}/#{sqlfile}"
end
end
end

0 comments on commit dce62e3

Please sign in to comment.