class Wordmove::Deployer::SSH

Attributes

local_backup_path[R]
local_dump_path[R]
local_gzipped_backup_path[R]
local_gzipped_dump_path[R]

Public Class Methods

new(environment, options) click to toggle source
Calls superclass method Wordmove::Deployer::Base::new
# File lib/wordmove/deployer/ssh.rb, line 11
def initialize(environment, options)
  super(environment, options)
  ssh_options = remote_options[:ssh]

  if simulate? && ssh_options[:rsync_options]
    ssh_options[:rsync_options].concat(" --dry-run")
  elsif simulate?
    ssh_options[:rsync_options] = "--dry-run"
  end

  @copier = Photocopier::SSH.new(ssh_options).tap { |c| c.logger = logger }

  @local_dump_path = local_wp_content_dir.path("dump.sql")
  @local_backup_path = local_wp_content_dir.path("local-backup-#{Time.now.to_i}.sql")
  @local_gzipped_dump_path = local_dump_path + '.gz'
  @local_gzipped_backup_path = local_wp_content_dir
                               .path("#{environment}-backup-#{Time.now.to_i}.sql.gz")
end

Private Instance Methods

download_remote_db(local_gizipped_dump_path) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 76
def download_remote_db(local_gizipped_dump_path)
  remote_dump_path = remote_wp_content_dir.path("dump.sql")
  # dump remote db into file
  remote_run mysql_dump_command(remote_options[:database], remote_dump_path)
  remote_run compress_command(remote_dump_path)
  remote_dump_path += '.gz'
  # download remote dump
  remote_get(remote_dump_path, local_gizipped_dump_path)
  remote_delete(remote_dump_path)
end
import_remote_dump(local_gizipped_dump_path) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 87
def import_remote_dump(local_gizipped_dump_path)
  remote_dump_path = remote_wp_content_dir.path("dump.sql")
  remote_gizipped_dump_path = remote_dump_path + '.gz'

  remote_put(local_gizipped_dump_path, remote_gizipped_dump_path)
  remote_run uncompress_command(remote_gizipped_dump_path)
  remote_run mysql_import_command(remote_dump_path, remote_options[:database])
  remote_delete(remote_dump_path)
end
pull_db() click to toggle source
Calls superclass method Wordmove::Deployer::Base#pull_db
# File lib/wordmove/deployer/ssh.rb, line 42
def pull_db
  super

  return true if simulate?

  backup_local_db!
  adapt_remote_db!
  after_pull_cleanup!
end
pull_exclude_paths(task) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 153
def pull_exclude_paths(task)
  Pathname.new(send(:"remote_#{task}_dir").relative_path)
          .dirname
          .ascend
          .each_with_object([]) do |directory, array|
            path = directory.to_path
            path.prepend('/') unless path.match? %r{^/}
            path.concat('/') unless path.match? %r{/$}
            path.concat('*')
            array << path
          end
          .concat(paths_to_exclude)
          .concat(['/*'])
end
pull_include_paths(task) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 142
def pull_include_paths(task)
  Pathname.new(send(:"remote_#{task}_dir").relative_path)
          .ascend
          .each_with_object([]) do |directory, array|
            path = directory.to_path
            path.prepend('/') unless path.match? %r{^/}
            path.concat('/') unless path.match? %r{/$}
            array << path
          end
end
push_db() click to toggle source
Calls superclass method Wordmove::Deployer::Base#push_db
# File lib/wordmove/deployer/ssh.rb, line 32
def push_db
  super

  return true if simulate?

  backup_remote_db!
  adapt_local_db!
  after_push_cleanup!
end
push_exclude_paths(task) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 127
def push_exclude_paths(task)
  Pathname.new(send(:"local_#{task}_dir").relative_path)
          .dirname
          .ascend
          .each_with_object([]) do |directory, array|
            path = directory.to_path
            path.prepend('/') unless path.match? %r{^/}
            path.concat('/') unless path.match? %r{/$}
            path.concat('*')
            array << path
          end
          .concat(paths_to_exclude)
          .concat(['/*'])
end
push_inlcude_paths(task) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 116
def push_inlcude_paths(task)
  Pathname.new(send(:"local_#{task}_dir").relative_path)
          .ascend
          .each_with_object([]) do |directory, array|
            path = directory.to_path
            path.prepend('/') unless path.match? %r{^/}
            path.concat('/') unless path.match? %r{/$}
            array << path
          end
end
remote_run(command) click to toggle source
# File lib/wordmove/deployer/ssh.rb, line 62
def remote_run(command)
  logger.task_step false, command
  return true if simulate?

  _stdout, stderr, exit_code = @copier.exec! command

  return true if exit_code.zero?

  raise(
    ShellCommandError,
    "Error code #{exit_code} returned by command \"#{command}\": #{stderr}"
  )
end