Skip to content

Instantly share code, notes, and snippets.

@febuiles
Created November 11, 2008 19:12
Show Gist options
  • Select an option

  • Save febuiles/23936 to your computer and use it in GitHub Desktop.

Select an option

Save febuiles/23936 to your computer and use it in GitHub Desktop.
# Backup database
namespace :db do
desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
mysql_password = Capistrano::CLI.password_prompt("Production MySQL password: ")
timestamp_string = Time.now.strftime("%Y%m%d%H%M%S")
filename = "#{application}.dump.#{timestamp_string}.sql.bz2"
file = "/tmp/#{filename}"
on_rollback { "rm -f #{file}" }
run "mysqldump -u #{user} --password=#{mysql_password} vom_production | bzip2 -c > #{file}" do |ch, stream, data|
puts data
end
`mkdir -p #{File.dirname(__FILE__)}/../backups/`
download file, "backups/#{filename}"
"rm -f #{file}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment