Class: SdbBackup::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sdb-backup/cli.rb

Instance Method Summary collapse

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sdb-backup/cli.rb', line 8

def run

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: sdb-backup [options]"

    opts.on("-f", "--from=[sdb|xml]", "Backup source") do |f|
      options[:from] = f
    end

    opts.on("-t", "--to=[sdb|xml]", "Backup destination") do |t|
      options[:to] = t end

    opts.on("-c", "--config=<filename>", "YAML configuration file") do |c|
      options[:config_file] = c
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end.parse!

  puts options
  puts options[:source]

  config = YAML.load_file(options[:config_file])
  puts config.inspect

  case options[:from]
  when "sdb"
    reader = SdbBackup::Reader::SdbDomain.new(AWS::SimpleDB.new(config['source']['sdb']))
  when "xml"
    puts "Reader not supported"
    exit
  end

  case options[:to]
  when "sdb"
    writer = SdbBackup::Writer::SdbDomain.new(AWS::SimpleDB.new(config['destination']['sdb']))
  when "xml"
    puts "Writer not supported"
    exit
  end

  sdb_backup = SdbBackup.new(reader, writer)
  sdb_backup.perform

end