Class: Restore

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/restore.rb

Overview

Restore a mogbak backup to a MogileFS domain

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#check_backup_path, #check_mogile_domain, #check_settings_file, #connect_sqlite, #create_sqlite_db, #migrate_sqlite, #mogile_db_connect, #mogile_tracker_connect

Constructor Details

#initialize(o = {}) ⇒ Restore

Returns a new instance of Restore.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restore.rb', line 7

def initialize(o={})
  @domain = o[:domain] if o[:domain]
  @tracker_ip = o[:tracker_ip] if o[:tracker_ip]
  @tracker_port = o[:tracker_port] if o[:tracker_port]
  @backup_path = o[:backup_path] if o[:backup_path]
  @workers = o[:workers] if o[:workers]


  #If settings file does not exist then this is not a valid mogilefs backup
  check_settings_file('settings.yml not found in path.  This must not be a backup profile. Cannot restore')

  connect_sqlite
  migrate_sqlite
  mogile_tracker_connect

  #Now that database is all setup load the model classes
  require ('domain')
  require('file')
  require('bakfile')
  require('fileclass')
end

Instance Attribute Details

#backup_pathObject

Returns the value of attribute backup_path.



3
4
5
# File 'lib/restore.rb', line 3

def backup_path
  @backup_path
end

#domainObject

Returns the value of attribute domain.



3
4
5
# File 'lib/restore.rb', line 3

def domain
  @domain
end

#tracker_hostObject

Returns the value of attribute tracker_host.



3
4
5
# File 'lib/restore.rb', line 3

def tracker_host
  @tracker_host
end

#tracker_portObject

Returns the value of attribute tracker_port.



3
4
5
# File 'lib/restore.rb', line 3

def tracker_port
  @tracker_port
end

#workersObject

Returns the value of attribute workers.



3
4
5
# File 'lib/restore.rb', line 3

def workers
  @workers
end

Instance Method Details

#launch_restore_workers(files) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/restore.rb', line 37

def launch_restore_workers(files)
  child = Proc.new { |files|
    results = []
    files.each do |file|
      break if file.nil?
      break if SignalHandler.instance.should_quit
      save = file.restore
      output_save(save, file.fid)
      results << {:restored => save, :fid => file.fid}
    end
    results
  }

  parent = Proc.new { |results|
    SqliteActiveRecord.clear_active_connections!
  }

  Forkinator.hybrid_fork(self.workers.to_i, files, parent, child)

end

#output_save(save, fid) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/restore.rb', line 29

def output_save(save, fid)
  if save
    Log.instance.info("Restored: FID #{fid}")
  else
    Log.instance.info("Error: FID #{fid}")
  end
end

#restore(dkey = false) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/restore.rb', line 58

def restore(dkey = false)
  if dkey
    file = BakFile.find_by_dkey(dkey)
    raise 'file not found in backup' unless file
    save = file.restore
    output_save(save, file.fid)
  else

    BakFile.find_in_batches(:conditions => ['saved = ?', true], :batch_size => 2000) do |batch|
      launch_restore_workers(batch)
      break if SignalHandler.instance.should_quit
    end

  end
end