I have some database tasks which work fantastically for my standard stages (beta, deploy).
They're doing things like triggering a backup, downloading it and restoring.
that's great for getting the production db and copying it up to beta.
I'd like to be able to restore the backup on my local development machine too. Is there a sensible way I can do this?
something like?
cap development db:restore
how would I set up my development stage to say 'connect on localhost, don't worry about ssh'
the restore task is...
desc 'restore backup'
task :restore do
on primary :web do
raise "Cant restore to production without deleting this line\n" if (fetch(:stage) == :production)
backup_file = "tmp/rails_database.tar"
backup_destination = "#{shared_path}/tmp/rails_database.tar"
upload! backup_file, backup_destination
execute "tar -xvf #{backup_destination} -C #{shared_path}/tmp --strip-components=2"
execute :rm, backup_destination
sql_file = "#{shared_path}/tmp/MySQL.sql.gz"
secrets = current_secrets(fetch(:stage).to_s)
mysql_command = mysql(secrets)
execute "gzip -d -c #{sql_file} | #{mysql_command}"
end
end
thank you!
Versions:
- Ruby 2.4.2
- Capistrano 3.9.1
- Rails 5.1
Platform: