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



52
53
54
# File 'lib/synco/command/rotate.rb', line 52

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

#backup_timestampObject



42
43
44
45
46
47
48
49
50
# File 'lib/synco/command/rotate.rb', line 42

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

#invoke(parent) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/synco/command/rotate.rb', line 56

def invoke(parent)
	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