Forked from rgo/capistrano_db_dump_and_clone_to_local.rb
Last active
December 20, 2015 15:19
-
-
Save akonwi/6153759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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