module MorpheusHeroku::Fetch

Public Instance Methods

run() click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 7
def run
  generate_backup!
  download_backup!
end

Private Instance Methods

create_dir(dir_name) click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 30
def create_dir(dir_name)
  return if Dir.exist?(dir_name)

  Helper.bash_run(command: "mkdir #{dir_name}")
end
create_file(file_name) click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 36
def create_file(file_name)
  return if File.exist?(file_name)

  Helper.bash_run(command: "touch #{file_name}")
end
download_backup!() click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 18
def download_backup!
  prepare_location
  Helper.bash_run(command: "curl -o #{backup_location} `heroku pg:backups public-url -a #{app_name}`")
end
generate_backup!() click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 14
def generate_backup!
  Helper.heroku_run(command: "heroku pg:backups capture")
end
prepare_location() click to toggle source
# File lib/morpheus-heroku/fetch.rb, line 23
def prepare_location
  return if File.writable?(backup_location)

  create_dir(backup_location[/^.+(?=\/)/])
  create_file(backup_location[/(?<=\/).+$/])
end