Sha256: 89a9fbb948cedaae2fa55ce860fc26a538992d930a7201e644dbe24cf97764dc

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/env ruby

fail_gently = ARGV.include?("--fail-gently")

if ARGV.include?("-i")
  puts "*******************************************************"
  puts
  system("du -sh ~/dumps")
  puts
  puts "*******************************************************"
  exit
end

require "yaml"

config_path = 'config/database.yml'
unless File.exist?(config_path) 
  if fail_gently
    puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    puts "*                                                             *"
    puts "*                                                             *"
    puts "*     Script is not called from inside a Rails project,       *"
    puts "*                                                             *"
    puts "*            THE DATABASE WILL NOT BE DUMPED.                 *"
    puts "*                                                             *"
    puts "*                                                             *"
    puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    sleep 5
    exit
  else
    raise "Call me from inside a Rails project."
  end
end
config = YAML::load(File.open(config_path))

environment = ARGV.reject{ |arg| arg[0].chr == '-' }.first || 'production'
config = config[environment] or raise "No production environment found. Please do `dumple [env_name]`"

dump_dir = "#{ENV['HOME']}/dumps"
unless File.directory?(dump_dir)
  Dir.mkdir(dump_dir)
  system("chmod 700 #{dump_dir}")
end
dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"

puts
puts "Dumping database for environment \"#{environment}\"..."

system "mysqldump -u\"#{config['username']}\" -p\"#{config['password']}\" #{config['database']} -r #{dump_path}"
system "chmod 600 #{dump_path}"

dump_size_kb = (File.size(dump_path) / 1024).round

puts "Dumped to #{dump_path} (#{dump_size_kb} KB)"
puts

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geordi-0.2.3 bin/dumple
geordi-0.2.2 bin/dumple
geordi-0.2.1 bin/dumple
geordi-0.2.0 bin/dumple
geordi-0.1.1 bin/dumple
geordi-0.1.0 bin/dumple