Skip to content

Instantly share code, notes, and snippets.

@patbenatar
Created July 6, 2012 21:43
Show Gist options
  • Save patbenatar/3062920 to your computer and use it in GitHub Desktop.
Save patbenatar/3062920 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
require 'fileutils'
YAML::ENGINE.yamler = 'psych'
RAILS_ENV = ENV["RAILS_ENV"]
path_to_database_yml = File.join("config", "database.yml")
config = YAML.load_file(path_to_database_yml)[RAILS_ENV]
system "mysqldump -u#{config["username"]} -p#{config["password"]} #{config["database"]} --lock-tables=false"
#!/usr/bin/env ruby
# Usage: receives a mysqldump via pipe
require 'yaml'
require 'fileutils'
YAML::ENGINE.yamler = 'psych'
RAILS_ENV = ENV["RAILS_ENV"]
path_to_database_yml = File.join("config", "database.yml")
config = YAML.load_file(path_to_database_yml)[RAILS_ENV]
`mysql -u#{config["username"]} -p#{config["password"]} #{config["database"]}`
namespace :copy do
task :db, roles: :app do
run "cd #{current_path} && ssh user@production 'cd #{current_path} && ./script/mysql_dump | gzip -c' | gunzip -c | ./script/mysql_import"
end
task :uploads, roles: :app do
# Copy system/uploads from prod to stg
path_to_system_uploads = "/home/deployer/apps/app_name/shared/system/uploads/"
run "(ssh user@production 'cd #{path_to_system_uploads} && tar -cf - .') | (cd #{path_to_system_uploads} && tar -xpf -)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment