Class: Remotebackup::Restore

Inherits:
Object
  • Object
show all
Defined in:
lib/remotebackup.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file, config_out_dir) ⇒ Restore

Returns a new instance of Restore.



214
215
216
217
218
219
# File 'lib/remotebackup.rb', line 214

def initialize(config_file,config_out_dir)
  @config_file = config_file
  @file_info_map = YAML.load_file(config_file)
  @config_out_dir = config_out_dir
  FileUtils.mkdir_p(@config_out_dir)
end

Instance Method Details

#startObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/remotebackup.rb', line 220

def start
  msg_out "-------------------------------------------"
  msg_out "Restore start #{File.dirname(@config_file)}"
  msg_out "-------------------------------------------"
  @file_info_map["directory"].each do |dir|
    msg_out "mkdir -p #{@config_out_dir}/#{dir}"
    FileUtils.mkdir_p(@config_out_dir + "/" + dir)
  end
  @file_info_map["symbolic"].each do |key,val|
    FileUtils.rm_r([@config_out_dir + "/" + key],{:force=>true})
    msg_out "link -s  #{val['source']} #{@config_out_dir}/#{key}"
    FileUtils.symlink(val["source"],@config_out_dir + "/" + key)
  end
  @file_info_map["file"].each do |key,val|
    unless val['file_name']
      $log.error("#{key} can't copy. ignore.")
      next
    end
    msg_out "cp #{val['file_name']} #{@config_out_dir}/#{key}"
    FileUtils.cp(val["file_name"],@config_out_dir + "/" + key)
  end
end