Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WordPress] add task to pull medias & pull database #14

Open
gido opened this issue May 19, 2022 · 0 comments
Open

[WordPress] add task to pull medias & pull database #14

gido opened this issue May 19, 2022 · 0 comments

Comments

@gido
Copy link
Member

gido commented May 19, 2022

💬 Is your feature request related to a problem? Please describe.

Add capistrano tasks to download WordPress medias and download a database dump.

We already have some of them in capdrupal:
https://github.com/antistatique/capdrupal/blob/41db72b62680d74ce524c6cf6f9e5a3feecf173b/lib/capdrupal.rb#L263-L275

@Yago found (very) old capistrano tasks:

# Sync media files
  desc 'Sync all media files'
  task :media do
    system "rsync -avz ./src/uploads #{fetch(:user)}@#{fetch(:host)}:#{shared_path}/"
  end

  # Pull media files
  desc 'Pull all media files'
  task :mediapull do
    system "rsync -avz #{fetch(:user)}@#{fetch(:host)}:#{shared_path}/uploads ./src/"
  end


  # Push local DB to remote
  desc 'Push local DB to remote'
  task :push do
    set :confirmed, proc {
      puts <<-WARN

========================================================================
  WARNING: You're about to overwrite the remote database !
========================================================================

      WARN
      ask :answer, "Are you sure you want to continue? y/N"
      if fetch(:answer)== 'y' then
        system "mysqldump --no-create-db --add-drop-database -u #{fetch(:database)[fetch(:stage)][:local][:user]} #{fetch(:database)[fetch(:stage)][:local][:name]} > dump.#{fetch(:stage)}.#{time}.sql"
        system "scp dump.#{fetch(:stage)}.#{time}.sql #{fetch(:user)}@#{fetch(:host)}:#{fetch(:home)}/dump/#{fetch(:application)}/local/"
        on roles(:web) do
          execute "mysql -u #{fetch(:database)[fetch(:stage)][:remote][:user]} --password=#{fetch(:database)[fetch(:stage)][:remote][:password]} #{fetch(:database)[fetch(:stage)][:remote][:name]} < #{fetch(:home)}/dump/#{fetch(:application)}/local/dump.#{fetch(:stage)}.#{time}.sql"
        end
        system "rm dump.#{fetch(:stage)}.#{time}.sql"
      else
        puts "\nCancelled!"
        exit
      end
    }.call
  end

  # Pull remote DB to local
  desc 'Pull remote DB to local'
  task :pull do
    set :confirmed, proc {
      puts <<-WARN

========================================================================
  WARNING: You're about to overwrite the local database !
========================================================================

      WARN
      ask :answer, "Are you sure you want to continue? y/N"
      if fetch(:answer)== 'y' then
        on roles(:web) do
          execute "mysqldump --no-create-db --add-drop-database -u #{fetch(:database)[fetch(:stage)][:remote][:user]} --password=#{fetch(:database)[fetch(:stage)][:remote][:password]} #{fetch(:database)[fetch(:stage)][:remote][:name]} > #{fetch(:home)}/dump/#{fetch(:application)}/remote/dump.#{fetch(:stage)}.#{time}.sql"
        end
        system "scp #{fetch(:user)}@#{fetch(:host)}:#{fetch(:home)}/dump/#{fetch(:application)}/remote/dump.#{fetch(:stage)}.#{time}.sql ./"
        system "mysql -u #{fetch(:database)[fetch(:stage)][:local][:user]} #{fetch(:database)[fetch(:stage)][:local][:name]} < dump.#{fetch(:stage)}.#{time}.sql"
        system "rm dump.#{fetch(:stage)}.#{time}.sql"
      else
        puts "\nCancelled!"
        exit
      end
    }.call
  end

We don't necessary the direct load of the downloaded db but getting a staging dump could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant