Class: Roma::SafeCopy
- Inherits:
-
Object
- Object
- Roma::SafeCopy
- Defined in:
- lib/roma/tools/cpdb.rb
Instance Attribute Summary collapse
-
#storages ⇒ Object
readonly
Returns the value of attribute storages.
Instance Method Summary collapse
- #backup(hname) ⇒ Object
- #backup_all ⇒ Object
- #check_storage_type ⇒ Object
- #close ⇒ Object
- #get_safecopy_stats(hname) ⇒ Object
- #get_storage_info ⇒ Object
-
#initialize(addr, port) ⇒ SafeCopy
constructor
A new instance of SafeCopy.
- #set_gui_last_snapshot ⇒ Object
- #set_gui_run_snapshot_status(status) ⇒ Object
- #set_storage_status(hname, num, stat) ⇒ Object
- #stats(regexp = "storage") ⇒ Object
- #wait(hname, num, stat) ⇒ Object
Constructor Details
#initialize(addr, port) ⇒ SafeCopy
Returns a new instance of SafeCopy.
10 11 12 13 14 |
# File 'lib/roma/tools/cpdb.rb', line 10 def initialize(addr, port) @con = TCPSocket.open(addr, port) set_gui_run_snapshot_status('true') get_storage_info end |
Instance Attribute Details
#storages ⇒ Object (readonly)
Returns the value of attribute storages.
8 9 10 |
# File 'lib/roma/tools/cpdb.rb', line 8 def storages @storages end |
Instance Method Details
#backup(hname) ⇒ Object
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 57 58 |
# File 'lib/roma/tools/cpdb.rb', line 32 def backup(hname) stat = get_safecopy_stats(hname) if stat.uniq != [:normal] puts "storages[#{hname}].storage.safecopy_stats #{stat.to_s}" puts "ERROR: Status except the :normal exists." return end @storages[hname].each_with_index do |fname, num| ret = set_storage_status(hname, num, "safecopy") if ret != "PUSHED\r\n" puts ret puts "ERROR: Can't change storage status to safecopy." return end wait(hname, num, :safecopy_flushed) puts "copy file : #{fname}" # file copy `cp #{fname} #{fname}.#{Time.now.strftime("%Y%m%d%H%M%S")}` ret = set_storage_status(hname, num, "normal") if ret != "PUSHED\r\n" puts ret puts "ERROR: Can't change storage status to normal." return end wait(hname, num, :normal) end end |
#backup_all ⇒ Object
16 17 18 19 20 |
# File 'lib/roma/tools/cpdb.rb', line 16 def backup_all @storages.keys.each do |k| backup(k) end end |
#check_storage_type ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/roma/tools/cpdb.rb', line 22 def check_storage_type stats('st_class') do |line| storage_type = line.match(/storages\[.+\]\.storage\.st_class\s(.+)/)[1].chomp unless storage_type =~ /^(TCStorage)$/ puts "ERROR:cpdb supports just TCStorage system, your storage type is #{storage_type}" exit end end end |
#close ⇒ Object
111 112 113 114 |
# File 'lib/roma/tools/cpdb.rb', line 111 def close set_gui_run_snapshot_status('false') @con.close if @con end |
#get_safecopy_stats(hname) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/roma/tools/cpdb.rb', line 80 def get_safecopy_stats(hname) ret = nil stats do |line| if /^storages\[#{hname}\]\.storage\.safecopy_stats\s(.+)/ =~ line ret = $1.chomp end end eval ret end |
#get_storage_info ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/roma/tools/cpdb.rb', line 69 def get_storage_info @storages = {} stats do |line| if /^storages\[(.+)\]\.storage\[(\d+)\]\.path\s(.+)/ =~ line @storages[$1] = [] unless @storages.key? $1 @storages[$1][$2.to_i] = $3.chomp # puts "#{$1} #{$2} #{$3}" end end end |
#set_gui_last_snapshot ⇒ Object
100 101 102 103 104 |
# File 'lib/roma/tools/cpdb.rb', line 100 def set_gui_last_snapshot t = Time.now.strftime('%Y/%m/%dT%H:%M:%S') @con.puts "set_gui_last_snapshot #{t}\r\n" @con.gets end |
#set_gui_run_snapshot_status(status) ⇒ Object
95 96 97 98 |
# File 'lib/roma/tools/cpdb.rb', line 95 def set_gui_run_snapshot_status(status) @con.puts "set_gui_run_snapshot #{status}\r\n" @con.gets end |
#set_storage_status(hname, num, stat) ⇒ Object
90 91 92 93 |
# File 'lib/roma/tools/cpdb.rb', line 90 def set_storage_status(hname, num, stat) @con.puts "set_storage_status #{num} #{stat} #{hname}\r\n" @con.gets end |
#stats(regexp = "storage") ⇒ Object
106 107 108 109 |
# File 'lib/roma/tools/cpdb.rb', line 106 def stats(regexp = "storage") @con.puts "stat #{regexp}\r\n" yield $_ while @con.gets != "END\r\n" end |
#wait(hname, num, stat) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/roma/tools/cpdb.rb', line 60 def wait(hname, num, stat) print "waiting for storages[#{hname}][#{num}] == #{stat} " while get_safecopy_stats(hname)[num] != stat print "." sleep 5 end puts end |