For local tasks, simply use Rake. Because Capistrano sub-classes Rake, and
your Capfile is a Rakefile with a different name, you can do the following:
namespace :db do
task :something_local do
sh "anything you like"
end
end
#sh comes from Rake, and is documented here:
- http://www.rubydoc.info/gems/rake/FileUtils#sh-instance_method
You lose a little of the logging niceness from Airbrussh/SSHKit, but
there's no SSH in the game, so I think it's acceptable that hostnames/IPs,
etc are not logged, as it's implicit.
Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667
On 6 December 2017 at 11:30, Rob Jonson <[email protected]> wrote:
> 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:
>
> - Mac OS
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Capistrano" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web, visit https://groups.google.com/d/
> msgid/capistrano/c5d48803-c211-48e1-aef0-9b701392febb%40googlegroups.com
> <https://groups.google.com/d/msgid/capistrano/c5d48803-c211-48e1-aef0-9b701392febb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/capistrano/CAN_%2BVLW38RyS5WK3YAH46Gp2ZAKu2yPR9ReQB_4q3hVcqBYYKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.