-
-
Save aaronmcadam/9546118 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
require 'net/scp' | |
namespace :db do | |
desc 'pull the latest backup & restore locally' | |
task :restore do | |
Rake::Task['db:download'].invoke | |
Rake::Task['db:replace'].invoke | |
end | |
desc 'pull down the lastest backup from production' | |
task :download do | |
Net::SCP.download!("example.org", "user", "path/to/latest.tar.gz", "latest.tar.gz", :verbose => true) do |ch, name, sent, total| | |
puts "#{name}: #{sent}/#{total}" | |
end | |
puts 'gunzipping...' | |
system *%W[gunzip -f latest.tar.gz] | |
end | |
desc 'restore a production backup locally' | |
task :replace => :environment do | |
puts 'dropping and re-creating db...' | |
Rake::Task['db:drop'].invoke | |
Rake::Task['db:create'].invoke | |
puts 'importing...' | |
db_name = Rails.configuration.database_configuration[Rails.env]['database'] | |
system *%W[pg_restore --verbose --no-owner --dbname #{db_name} latest.tar] | |
puts 'all done!' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment