Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save akonwi/6153759 to your computer and use it in GitHub Desktop.

Select an option

Save akonwi/6153759 to your computer and use it in GitHub Desktop.
# With these tasks you can:
# - dump your production database and save it in shared_path/db_backups
# - download most recent backup
namespace :db do
task :backup_name, :roles => :db, :only => { :primary => true } do
now = Time.now
run "mkdir -p #{shared_path}/db_backups"
backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
set :backup_file, "#{shared_path}/db_backups/#{application}-snapshot-#{backup_time}.sql"
end
desc "Backup your MySQL database to shared_path+/db_backups"
task :dump, :roles => :db, :only => {:primary => true} do
backup_name
run "mysqldump -u root -p -h localhost #{application}_production > #{backup_file}" do |ch, stream, out |
ch.send_data "\n" if out=~ /^Enter password:/
end
end
desc "Download most recent database backup"
task :download_backup, :roles => :db, :only => {:primary => true} do
backup_name
dump
run_locally "mkdir -p ~/rails/#{application}_db_backup"
run_locally "scp deployer@intrnhuntr.com:#{backup_file} ~/rails/#{application}_db_backup/#{application}_remote.sql"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment