Class: Dabcup::Operation::Populate

Inherits:
Base
  • Object
show all
Defined in:
lib/dabcup/operation/populate.rb

Instance Attribute Summary

Attributes inherited from Base

#database

Instance Method Summary collapse

Methods inherited from Base

#best_dumps_path, #best_local_dumps_path, #check, #initialize, #remove_local_dump?, #same_ssh_as_database?, #terminate

Constructor Details

This class inherits a constructor from Dabcup::Operation::Base

Instance Method Details

#run(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dabcup/operation/populate.rb', line 4

def run(args)
  now = Time.now
  days_before = args[2].to_i
  local_file_name = Dabcup::Database::dump_name(database)
  local_file_path = File.join(Dir.tmpdir, local_file_name)
  database.dump(local_file_path)
  for day_before in (0 .. days_before)
    remote_file_name = Dabcup::Database::dump_name(database, now - (day_before * 24 * 3600))
    main_storage.put(local_file_path, remote_file_name)
    spare_storage.put(local_file_path, remote_file_name) if spare_storage
  end
  ensure
    File.delete(local_file_path) if local_file_path and File.exists?(local_file_path)
end