Module: Backup::S3Helper

Included in:
S3
Defined in:
lib/capistrano/ops/rails/lib/backup/s3_helper.rb

Instance Method Summary collapse

Instance Method Details

#calculate_chunk_size(total_size) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 33

def calculate_chunk_size(total_size)
  max_chunks = 10_000
  min_chunk_size = 50 * 1024 * 1024 # 50MB
  max_chunk_size = 105 * 1024 * 1024 # 105MB
  chunk_size = [total_size / max_chunks, min_chunk_size].max
  [chunk_size, max_chunk_size].min
end

#calculate_total_size(folder_path) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 25

def calculate_total_size(folder_path)
  total_size = 0
  Find.find(folder_path) do |file_path|
    total_size += File.size(file_path) unless File.directory?(file_path)
  end
  total_size
end

#get_current_month(all_items) ⇒ Object



17
18
19
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 17

def get_current_month(all_items)
  all_items.select { |item| item[:last_modified].strftime('%Y-%m') == Time.now.strftime('%Y-%m') }
end

#get_delete_items(items, keep) ⇒ Object



5
6
7
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 5

def get_delete_items(items, keep)
  items.slice(keep..-1)
end

#get_items_by_month(all_items, month) ⇒ Object



21
22
23
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 21

def get_items_by_month(all_items, month)
  all_items.select { |item| item[:last_modified].strftime('%Y-%m') == month }
end

#get_months(all_items) ⇒ Object



9
10
11
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 9

def get_months(all_items)
  all_items.reverse.map { |m| m[:last_modified].strftime('%Y-%m') }
end

#get_old_months(months) ⇒ Object



13
14
15
# File 'lib/capistrano/ops/rails/lib/backup/s3_helper.rb', line 13

def get_old_months(months)
  months.uniq.reject { |m| m == Time.now.strftime('%Y-%m') }
end