23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/backuper.rb', line 23
def perform_files_backup
timestamp = "#{Time.now.strftime('%Y-%m-%d-%s')}"
local_current_backup_path = "#{local_backup_base_path}/files/#{timestamp}"
local_latest_backup_path = Dir["#{local_backup_base_path}/files/*"].sort.last
system "mkdir -p #{local_current_backup_path}"
if File.exist?("#{local_latest_backup_path}")
puts "Performing local backup with hard links to pervious version"
system "nice -n 10 rsync -az --delete --link-dest=#{local_latest_backup_path} #{source_path} #{local_current_backup_path}"
else
puts "Performing initial local backup"
system "nice -n 10 rsync -az #{source_path} #{local_current_backup_path}"
end
Dir["#{local_backup_base_path}/files/*"].sort.reverse.each_with_index do |backup_version, index|
if index >= max_kept_backups
system "rm -rf #{backup_version}"
end
end
end
|