master
 1set(:postgresql_host, "localhost")
 2
 3namespace :db do
 4  desc "Backup the database and copy it locally"
 5  task :backup do
 6    filename = "#{fetch(:rails_env)}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump"
 7    backup_path = "#{shared_path}/backups"
 8    ask(:postgresql_password, "default")
 9    on roles(:db) do
10      execute "mkdir -p #{shared_path}/backups"
11      execute "PGPASSWORD='#{fetch(:postgresql_password)}' pg_dump -Fc --no-acl --no-owner -h #{fetch(:postgresql_host)} -U deployer cakeside > #{backup_path}/#{filename}"
12      download!("#{backup_path}/#{filename}", "db/backups/", :via => :scp)
13      #execute "s3cmd sync #{shared_path}/backups/*.dump s3://#{ENV['AWS_S3_BACKUPS_BUCKET']}/#{fetch(:rails_env)}/pg/"
14    end
15  end
16end