Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/heroku_cloud_backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
def execute
log "heroku:backup started"

b = client.get_backups.last
b = last_backup
raise HerokuCloudBackup::Errors::NoBackups.new("You don't have any pgbackups. Please run heroku pgbackups:capture first.") if b.empty?

begin
Expand Down Expand Up @@ -42,6 +42,10 @@ def execute
log "heroku:backup complete"
end

def last_backup
client.get_backups.sort{|snap1, snap2| Time.parse(snap1['created_at']) <=> Time.parse(snap2['created_at']) }.last
end

def connection=(connection)
@connection = connection
end
Expand Down Expand Up @@ -114,12 +118,13 @@ def prune
files = directory.files.all(:prefix => backup_path)
file_count = 0
files.reverse.each do |file|
if file.key =~ Regexp.new("/#{backup_path}\/\d{4}-\d{2}-\d{2}-\d{6}\.sql\.gz$/i")
if file.key =~ /#{backup_path}.*\/\d{4}-\d{2}-\d{2}-\d{6}.dump$/i
file_count += 1
else
next
end
if file_count > number_of_files
if file_count > number_of_files.to_i
puts "prune destroying file #{file.key}"
file.destroy
end
end
Expand Down