Class: ModuleHouse
Overview
-
module: ufriend host: 127.0.0.1 username: space password: spaceapptest datacenter_rootdir: space testing_rootdir: /home/space/space subfiles: conf/friend.conf subdirs: conf dbversion: 5.1.30 dbname: newfriend backsql: friend/friend_new.sql depends: albumlogic
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
-
#get_by_name(name) ⇒ Object
功能: 根据模块名取模块数据.
-
#rollback(name) ⇒ Object
功能: 进行环境的恢复.
-
#sync(name) ⇒ Object
功能: 进行数据同步.
Methods inherited from DataHouse
Constructor Details
This class inherits a constructor from DataHouse
Class Method Details
.get_instance ⇒ Object
231 232 233 234 |
# File 'lib/common/data_house.rb', line 231 def self.get_instance @@instance = new("module") unless @@instance @@instance end |
Instance Method Details
#get_by_name(name) ⇒ Object
功能: 根据模块名取模块数据
参数: name - 模块的名字
Example: mdl1 = ModuleHouse.get_instance.get_by_name “ufriend”
244 245 246 247 248 |
# File 'lib/common/data_house.rb', line 244 def get_by_name(name) @data_house.find do |u| u["module"] == name if u.key? "module" end end |
#rollback(name) ⇒ Object
功能: 进行环境的恢复
314 315 |
# File 'lib/common/data_house.rb', line 314 def rollback(name) end |
#sync(name) ⇒ Object
功能: 进行数据同步
参数name - 模块的名字
Example: ModuleHouse.get_instance.sync “ufriend”
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/common/data_house.rb', line 258 def sync(name) dc = DCHouse.get_instance.get_by_name("datacenter1") mdl = ModuleHouse.get_instance.get_by_name(name) if(mdl["host"]==nil || mdl["username"]==nil || mdl["password"]==nil || mdl["datacenter_rootdir"]==nil || mdl["testing_rootdir"]==nil) puts "Uncomplate Module conf file." return end #对每个subs cp,对每个数据库恢复 mdl["subfiles"]!=nil && subfiles = mdl["subfiles"].split mdl["subdirs"]!=nil && subdirs = mdl["subdirs"].split mdl["dbversion"]!=nil && dbversion = mdl["dbversion"].split mdl["dbname"]!=nil && dbname = mdl["dbname"].split mdl["backsql"]!=nil && backsql = mdl["backsql"].split mdl["depends"]!=nil && depends = mdl["depends"].split # 首先将所有依赖模块递归同步 if(depends!=nil) print "#{name} depends === " end depends!=nil && depends.uniq.each{ |depend_module| print " > #{depend_module}" } puts "" depends!=nil && depends.uniq.each{ |depend_module| puts "try to sync depends module: #{depend_module}" ModuleHouse.get_instance.sync "#{depend_module}" } # 同步本模块的数据文件 subfiles!=nil && subfiles.each{|dir| puts "try to transfer "+dc["host"]+":"+dc["datacenterpath"]+"/"+mdl["datacenter_rootdir"]+"/"+dir+" to "+mdl["host"]+"@"+mdl["testing_rootdir"]+"/"+dir Util.scpfromto dc["host"], dc["datacenterpath"]+"/"+mdl["datacenter_rootdir"]+"/"+dir, mdl["host"], mdl["testing_rootdir"]+"/"+dir, dc["username"], dc["password"], mdl["username"], mdl["password"] } subdirs!=nil && subdirs.each{|dir| puts "try to transfer "+dc["host"]+":"+dc["datacenterpath"]+"/"+mdl["datacenter_rootdir"]+"/"+dir+" to "+mdl["host"]+"@"+mdl["testing_rootdir"]+"/"+dir Util.scpfromtod dc["host"], dc["datacenterpath"]+"/"+mdl["datacenter_rootdir"]+"/"+dir, mdl["host"], mdl["testing_rootdir"]+"/"+dir, dc["username"], dc["password"], mdl["username"], mdl["password"] } # 同步本模块的数据库数据 backsql!=nil && backsql.each{|file| if mdl["dbversion"] == "5.1.30" puts "try to #{dc["db01"]["dbpath"]}/bin/mysql -u#{dc["db01"]["dbuser"]} -p#{dc["db01"]["dbpass"]} #{mdl["dbname"]} < #{dc["datacenterpath"]}/#{mdl["backsql"]}" ssh_cmd dc["host"], dc["username"], dc["password"], "#{dc["db01"]["dbpath"]}/bin/mysql -u#{dc["db01"]["dbuser"]} -p#{dc["db01"]["dbpass"]} #{mdl["dbname"]} < #{dc["datacenterpath"]}/#{mdl["backsql"]}" puts Context.get("IOBODY") end if mdl["dbversion"] == "5.22" puts "try to #{dc["db02"]["dbpath"]}/bin/mysql -u#{dc["db02"]["dbuser"]} -p#{dc["db02"]["dbpass"]} #{mdl["dbname"]} < #{dc["datacenterpath"]}/#{mdl["backsql"]}" ssh_cmd dc["host"], dc["username"], dc["password"], "#{dc["db02"]["dbpath"]}/bin/mysql -u#{dc["db02"]["dbuser"]} -p#{dc["db02"]["dbpass"]} #{mdl["dbname"]} < #{dc["datacenterpath"]}/#{mdl["backsql"]}" puts Context.get("IOBODY") end } end |