Skip to content

Commit

Permalink
Merge pull request #19 from antistatique/feature/wordpress-database
Browse files Browse the repository at this point in the history
Issue #14 : Add a task to pull a WordPress database
  • Loading branch information
gido authored Oct 3, 2024
2 parents 7f1f391 + 1f1ba6b commit 22dc2cb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ require 'capistrano/antistatique/drupal/sapi'
require 'capistrano/antistatique/drupal/newrelic'
require 'capistrano/antistatique/drupal/elasticsearch'

# Wordpress Tasks.
require 'capistrano/antistatique/wordpress'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined.
Dir.glob('config/capistrano/tasks/*.rake').each { |r| import r }
```
Expand Down
34 changes: 34 additions & 0 deletions lib/capistrano/tasks/wordpress.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,38 @@ namespace :wordpress do
end
end
end

namespace :database do
desc "Download database locally with datetime in filename"
task :download_locally do
on roles(:db) do |host|
datetime = Time.now.strftime("%Y%m%d_%H%M%S")
remote_sql_file = "#{fetch(:tmp_dir)}/wordpress_#{datetime}.sql.gz"
local_sql_file = "dump/#{fetch(:stage)}_wordpress_#{host.hostname}_#{datetime}.sql.gz"

# Prepare the destination dump dir.
run_locally do
execute "mkdir -p dump"
end

# run the SQL database export with wp-cli
within release_path do
execute :wp, "db export - | gzip > #{remote_sql_file}"
end

download! remote_sql_file, local_sql_file

# Cleanup.
execute "rm #{remote_sql_file}"

info ""
info "\e[32mDatabase downloaded locally in #{local_sql_file}\e[0m"
info "Execute the following command to import the database in the Docker dev environment:"
info ""
info "\e[33m docker compose exec dev wp db create\e[0m"
info "\e[33m gunzip -c #{local_sql_file} | docker compose exec -T dev wp db import -\e[0m"
info ""
end
end
end
end

0 comments on commit 22dc2cb

Please sign in to comment.