Class: Backup::Rotator

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/backup/rotator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor) ⇒ Rotator

Returns a new instance of Rotator.



11
12
13
14
# File 'lib/backup/rotator.rb', line 11

def initialize(actor)
  @actor = actor
  @configuration = actor.configuration
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



7
8
9
# File 'lib/backup/rotator.rb', line 7

def actor
  @actor
end

#configurationObject (readonly) Also known as: c

Returns the value of attribute configuration.



8
9
10
# File 'lib/backup/rotator.rb', line 8

def configuration
  @configuration
end

Class Method Details

.timestamped_prefix(name) ⇒ Object



122
123
124
# File 'lib/backup/rotator.rb', line 122

def self.timestamped_prefix(name)
  newname = Time.now.strftime("%Y-%m-%d-%H-%M-%S_") + File.basename(name)
end

Instance Method Details

#create_sons_today?Boolean

Returns:

  • (Boolean)


71
# File 'lib/backup/rotator.rb', line 71

def create_sons_today?;     is_today_a? :son_created_on;     end

#promote_fathers_today?Boolean

Returns:

  • (Boolean)


73
# File 'lib/backup/rotator.rb', line 73

def promote_fathers_today?; is_today_a? :father_promoted_on; end

#promote_sons_today?Boolean

Returns:

  • (Boolean)


72
# File 'lib/backup/rotator.rb', line 72

def promote_sons_today?;    is_today_a? :son_promoted_on;    end

#rotate_via_ftp(last_result) ⇒ Object

TODO



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/backup/rotator.rb', line 46

def rotate_via_ftp(last_result)
#      ftp = Backup::FtpActor.new(c) 
#      ftp.connect 
#
#      hierarchy.each do |m| 
#        dir = c[:backup_path] + "/" + m
#        ftp.verify_directory_exists(dir) 
#      end  
#
#      newname = timestamped_prefix(last_result)
#      ftp.run "mv #{last_result} #{place_in}/#{newname}"
#
#      ftp.cleanup_directory(place_in, how_many_to_keep_today)
#      ftp.close
end

#rotate_via_mv(last_result) ⇒ Object

Take the last result and rotate it via mv on the local machine



17
18
19
20
21
22
23
24
25
26
# File 'lib/backup/rotator.rb', line 17

def rotate_via_mv(last_result)
  # verify that each of the directories exist, grandfathers, fathers, sons
  hierarchy.each { |m| verify_local_backup_directory_exists(m) }

  # place todays backup into the specified directory with a timestamp. 
  newname = timestamped_prefix(last_result)
  sh "mv #{last_result} #{place_in}/#{newname}"

  cleanup_via_mv(place_in, how_many_to_keep_today)
end

#rotate_via_s3(last_result) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/backup/rotator.rb', line 62

def rotate_via_s3(last_result)
  s3 = Backup::S3Actor.new(c)
  s3.verify_rotation_hierarchy_exists(hierarchy)
  index = s3.rotation
  index[todays_generation] << last_result
  s3.rotation = index
  s3.cleanup(todays_generation, how_many_to_keep_today)
end

#rotate_via_ssh(last_result) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/backup/rotator.rb', line 28

def rotate_via_ssh(last_result)
  ssh = Backup::SshActor.new(c) 
  ssh.connect 
  ssh.run "echo \"#{last_result}\""

  hierarchy.each do |m| 
    dir = c[:backup_path] + "/" + m
    ssh.verify_directory_exists(dir) 
  end  

  newname = timestamped_prefix(last_result)
  ssh.run "mv #{last_result} #{place_in}/#{newname}"

  ssh.cleanup_directory(place_in, how_many_to_keep_today)
  ssh.close
end

#timestamped_prefix(name) ⇒ Object

Given name returns a timestamped version of name.



127
128
129
# File 'lib/backup/rotator.rb', line 127

def timestamped_prefix(name)
  Backup::Rotator.timestamped_prefix(name)
end

#todays_generationObject



117
118
119
120
# File 'lib/backup/rotator.rb', line 117

def todays_generation
  goes_in = promote_fathers_today? ? "grandfathers" :         \
            promote_sons_today?    ? "fathers"      : "sons"
end