class Object

Constants

COMMAND
DATA_SYNC

Public Instance Methods

dump_restore(rails_root, backup_path, mode: :dump, backend: :local) click to toggle source
# File lib/mina/data_sync/helpers.rb, line 39
def dump_restore(rails_root, backup_path, mode: :dump, backend: :local)
  comment %{#{mode == :dump ? 'Dumping' : 'Restoring'} database}
  command %{cd #{rails_root}}
  command DATA_SYNC.to_s
  command %{mkdir -p #{backup_path}}
  command %{CONFIG=$(RAILS_ENV=#{backend == :local ? 'development' : fetch(:rails_env)} bundle exec rails runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_json")}
  comment %{$(data_sync "#{mode}" "#{backup_path}/#{fetch(:backup_file)}" "$CONFIG")}
  command %{eval $(data_sync "#{mode}" "#{backup_path}/#{fetch(:backup_file)}" "$CONFIG")}
end
rsync_db(mode: :remote_to_local) click to toggle source
# File lib/mina/data_sync/helpers.rb, line 49
def rsync_db(mode: :remote_to_local)
  if mode == :remote_to_local
    run :local do
      comment %{Copying backup}
      command %{mkdir -p #{fetch(:local_backup_path)}}
      comment %{Backup: #{fetch(:local_backup_path)}/#{fetch(:backup_file)}}
      command %{rsync --progress -e "ssh -p #{fetch(:port, 22)}" #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)} #{fetch(:local_backup_path)}/#{fetch(:backup_file)}}
    end
  else
    run :remote do
      command %{mkdir -p #{fetch(:current_path)}/#{fetch(:remote_backup_path)}}
    end
    run :local do
      comment %{Copying backup}
      comment %{Backup: #{fetch(:remote_backup_path)}/#{fetch(:backup_file)}}
      command %{rsync --progress -e "ssh -p #{fetch(:port, 22)}" #{fetch(:local_backup_path)}/#{fetch(:backup_file)} #{fetch(:user)}@#{fetch(:domain)}:#{fetch(:current_path)}/#{fetch(:remote_backup_path)}/#{fetch(:backup_file)}}
    end
  end
end