Class: Dabcup::Operation::Restore

Inherits:
Base
  • Object
show all
Defined in:
lib/dabcup/operation/restore.rb

Instance Attribute Summary

Attributes inherited from Base

#database

Instance Method Summary collapse

Methods inherited from Base

#best_dumps_path, #best_local_dumps_path, #check, #initialize, #remove_local_dump?, #same_ssh_as_database?, #terminate

Constructor Details

This class inherits a constructor from Dabcup::Operation::Base

Instance Method Details

#restore_without_ssh(args) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dabcup/operation/restore.rb', line 8

def restore_without_ssh(args)
  raise Dabcup::Error.new("Not enough arguments. Try 'dabcup help restore'") if args.size < 3
  dump_name = args[2]
  dump_path = File.join(Dir.tmpdir, dump_name)
  if main_storage.exists?(dump_name)
    main_storage.get(dump_name, dump_path)
  elsif spare_storage and spare_storage.exists?(dump_name)
    spare_storage.get(dump_name, dump_path)
  else
    raise Dabcup::Error.new("Dump '#{dump_name}' not found.")
  end
  database.restore(dump_path)
end

#retore_with_ssh(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dabcup/operation/restore.rb', line 22

def retore_with_ssh(args)
  raise Dabcup::Error.new("Not enough arguments. Try 'dabcup help restore'") if args.size < 3
  dump_name = args[2]
  dump_path = File.join(main_storage.path, dump_name)
  local_dump_path = nil
  if not main_storage.exists?(dump_name)
    if spare_storage.is_a?(Dabcup::Storage::Local)
      local_dump_path = File.join(spare_storage.path, dump_name)
    else
      spare_storage.get(dump_name, local_dump_path)
    end
    main_storage.put(dump_path, dump_name) if not main_storage.exists?(dump_name)
  end
  database.restore(dump_path)
ensure
  #File.delete(local_dump_path) if local_dump_path and File.exists?(local_dump_path)
end

#run(args) ⇒ Object



4
5
6
# File 'lib/dabcup/operation/restore.rb', line 4

def run(args)
  database.via_ssh? ? restore_with_ssh(args) : restore_without_ssh(args)
end