Class: Synco::Command::Rotate

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/synco/command/rotate.rb

Instance Method Summary collapse

Instance Method Details

#backup_nameObject



37
38
39
# File 'lib/synco/command/rotate.rb', line 37

def backup_name
  backup_timestamp.strftime(@options[:format])
end

#backup_timestampObject



27
28
29
30
31
32
33
34
35
# File 'lib/synco/command/rotate.rb', line 27

def backup_timestamp
  timestamp = Time.now.utc
    
  #if timezone = @options[:timezone]
  #  timestamp = timestamp.in_time_zone(timezone)
  #end
    
  return timestamp
end

#callObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/synco/command/rotate.rb', line 41

def call
  snapshot_name = @options[:snapshot]
  unless File.exist? snapshot_name
    $stderr.puts "Snapshot directory #{snapshot_name} does not exist!"
    exit(10)
  end
    
  rotated_name = backup_name
  if File.exist? rotated_name
    $stderr.puts "Destination rotation name #{rotated_name} already exists!"
    exit(20)
  end
    
  puts "Rotating #{snapshot_name} to #{rotated_name} in #{Dir.pwd}"
    
  # Move rotated dir
  FileUtils.mv(snapshot_name, rotated_name)

  # Recreate latest symlink
  latest_link = @options[:latest]
  if File.symlink?(latest_link)
    puts "Removing old latest link..."
    FileUtils.rm(latest_link)
  end

  puts "Creating latest symlink to #{rotated_name}"
  FileUtils.ln_s(rotated_name, latest_link)
end