class Roma::SafeCopy
Attributes
storages[R]
Public Class Methods
new(addr, port)
click to toggle source
# File lib/roma/tools/cpdb.rb 10 def initialize(addr, port) 11 @con = TCPSocket.open(addr, port) 12 set_gui_run_snapshot_status('true') 13 get_storage_info 14 end
Public Instance Methods
backup(hname)
click to toggle source
# File lib/roma/tools/cpdb.rb 32 def backup(hname) 33 stat = get_safecopy_stats(hname) 34 if stat.uniq != [:normal] 35 puts "storages[#{hname}].storage.safecopy_stats #{stat.to_s}" 36 puts "ERROR: Status except the :normal exists." 37 return 38 end 39 @storages[hname].each_with_index do |fname, num| 40 ret = set_storage_status(hname, num, "safecopy") 41 if ret != "PUSHED\r\n" 42 puts ret 43 puts "ERROR: Can't change storage status to safecopy." 44 return 45 end 46 wait(hname, num, :safecopy_flushed) 47 puts "copy file : #{fname}" 48 # file copy 49 `cp #{fname} #{fname}.#{Time.now.strftime("%Y%m%d%H%M%S")}` 50 ret = set_storage_status(hname, num, "normal") 51 if ret != "PUSHED\r\n" 52 puts ret 53 puts "ERROR: Can't change storage status to normal." 54 return 55 end 56 wait(hname, num, :normal) 57 end 58 end
backup_all()
click to toggle source
# File lib/roma/tools/cpdb.rb 16 def backup_all 17 @storages.keys.each do |k| 18 backup(k) 19 end 20 end
check_storage_type()
click to toggle source
# File lib/roma/tools/cpdb.rb 22 def check_storage_type 23 stats('st_class') do |line| 24 storage_type = line.match(/storages\[.+\]\.storage\.st_class\s(.+)/)[1].chomp 25 unless storage_type =~ /^(TCStorage)$/ 26 puts "ERROR:cpdb supports just TCStorage system, your storage type is #{storage_type}" 27 exit 28 end 29 end 30 end
close()
click to toggle source
# File lib/roma/tools/cpdb.rb 111 def close 112 set_gui_run_snapshot_status('false') 113 @con.close if @con 114 end
get_safecopy_stats(hname)
click to toggle source
# File lib/roma/tools/cpdb.rb 80 def get_safecopy_stats(hname) 81 ret = nil 82 stats do |line| 83 if /^storages\[#{hname}\]\.storage\.safecopy_stats\s(.+)/ =~ line 84 ret = $1.chomp 85 end 86 end 87 eval ret 88 end
get_storage_info()
click to toggle source
# File lib/roma/tools/cpdb.rb 69 def get_storage_info 70 @storages = {} 71 stats do |line| 72 if /^storages\[(.+)\]\.storage\[(\d+)\]\.path\s(.+)/ =~ line 73 @storages[$1] = [] unless @storages.key? $1 74 @storages[$1][$2.to_i] = $3.chomp 75 # puts "#{$1} #{$2} #{$3}" 76 end 77 end 78 end
set_gui_last_snapshot()
click to toggle source
# File lib/roma/tools/cpdb.rb 100 def set_gui_last_snapshot 101 t = Time.now.strftime('%Y/%m/%dT%H:%M:%S') 102 @con.puts "set_gui_last_snapshot #{t}\r\n" 103 @con.gets 104 end
set_gui_run_snapshot_status(status)
click to toggle source
# File lib/roma/tools/cpdb.rb 95 def set_gui_run_snapshot_status(status) 96 @con.puts "set_gui_run_snapshot #{status}\r\n" 97 @con.gets 98 end
set_storage_status(hname, num, stat)
click to toggle source
# File lib/roma/tools/cpdb.rb 90 def set_storage_status(hname, num, stat) 91 @con.puts "set_storage_status #{num} #{stat} #{hname}\r\n" 92 @con.gets 93 end
stats(regexp = "storage") { |$_ while gets != "END\r\n"| ... }
click to toggle source
# File lib/roma/tools/cpdb.rb 106 def stats(regexp = "storage") 107 @con.puts "stat #{regexp}\r\n" 108 yield $_ while @con.gets != "END\r\n" 109 end
wait(hname, num, stat)
click to toggle source
# File lib/roma/tools/cpdb.rb 60 def wait(hname, num, stat) 61 print "waiting for storages[#{hname}][#{num}] == #{stat} " 62 while get_safecopy_stats(hname)[num] != stat 63 print "." 64 sleep 5 65 end 66 puts 67 end