FIX: Do not show backups stored in subfolder of bucket

This commit is contained in:
Gerhard Schlager 2019-01-24 21:58:36 +01:00
parent 7e9da812ea
commit 45b056b615
3 changed files with 18 additions and 2 deletions

View File

@ -59,7 +59,7 @@ module BackupRestore
objects = []
@s3_helper.list.each do |obj|
if obj.key.match?(/\.t?gz$/i)
if obj.key.match?(file_regex)
objects << create_file_from_object(obj)
end
end
@ -106,6 +106,19 @@ module BackupRestore
end
end
def file_regex
@file_regex ||= begin
path = @s3_helper.s3_bucket_folder_path || ""
if path.present?
path = "#{path}/" unless path.end_with?("/")
path = Regexp.quote(path)
end
/^#{path}[^\/]*\.t?gz$/i
end
end
def free_bytes
nil
end

View File

@ -30,6 +30,7 @@ describe BackupRestore::LocalBackupStore do
create_file(db_name: "default", filename: "a.tgz", last_modified: "2018-02-11T09:27:00Z", size_in_bytes: 29)
create_file(db_name: "default", filename: "r.sql.gz", last_modified: "2017-12-20T03:48:00Z", size_in_bytes: 11)
create_file(db_name: "default", filename: "no-backup.txt", last_modified: "2018-09-05T14:27:00Z", size_in_bytes: 12)
create_file(db_name: "default/subfolder", filename: "c.tar.gz", last_modified: "2019-01-24T18:44:00Z", size_in_bytes: 23)
create_file(db_name: "second", filename: "multi-2.tar.gz", last_modified: "2018-11-27T03:16:54Z", size_in_bytes: 19)
create_file(db_name: "second", filename: "multi-1.tar.gz", last_modified: "2018-11-26T03:17:09Z", size_in_bytes: 22)

View File

@ -101,7 +101,7 @@ describe BackupRestore::S3BackupStore do
prefix = context.params[:prefix]
if prefix.blank?
@objects.reject { |obj| obj[:key].include?("/") }
@objects.reject { |obj| obj[:key].include?("backups/") }
else
@objects.select { |obj| obj[:key].start_with?(prefix) }
end
@ -114,9 +114,11 @@ describe BackupRestore::S3BackupStore do
@objects << { key: "a.tgz", size: 29, last_modified: Time.parse("2018-02-11T09:27:00Z") }
@objects << { key: "r.sql.gz", size: 11, last_modified: Time.parse("2017-12-20T03:48:00Z") }
@objects << { key: "no-backup.txt", size: 12, last_modified: Time.parse("2018-09-05T14:27:00Z") }
@objects << { key: "subfolder/c.tar.gz", size: 23, last_modified: Time.parse("2019-01-24T18:44:00Z") }
@objects << { key: "backups/second/multi-2.tar.gz", size: 19, last_modified: Time.parse("2018-11-27T03:16:54Z") }
@objects << { key: "backups/second/multi-1.tar.gz", size: 22, last_modified: Time.parse("2018-11-26T03:17:09Z") }
@objects << { key: "backups/second/subfolder/multi-3.tar.gz", size: 23, last_modified: Time.parse("2019-01-24T18:44:00Z") }
end
def remove_backups