A platform for community discussion. Free, open, simple.
FIX: Do not show backups stored in subfolder of bucket
Gerhard Schlager45b056b6151e
diff --git a/lib/backup_restore/s3_backup_store.rb b/lib/backup_restore/s3_backup_store.rbindex 3ee6388f811..03edc014c38 100644--- a/lib/backup_restore/s3_backup_store.rb+++ b/lib/backup_restore/s3_backup_store.rb@@ -59,7 +59,7 @@ module BackupRestoreobjects = []@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)endend@@ -106,6 +106,19 @@ module BackupRestoreendend+ 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_bytesnilenddiff --git a/spec/lib/backup_restore/local_backup_store_spec.rb b/spec/lib/backup_restore/local_backup_store_spec.rbindex bd5f627c07a..440e0a6b964 100644--- a/spec/lib/backup_restore/local_backup_store_spec.rb+++ b/spec/lib/backup_restore/local_backup_store_spec.rb@@ -30,6 +30,7 @@ describe BackupRestore::LocalBackupStore docreate_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)diff --git a/spec/lib/backup_restore/s3_backup_store_spec.rb b/spec/lib/backup_restore/s3_backup_store_spec.rbindex 3bba9b9c327..b17f60916d2 100644--- a/spec/lib/backup_restore/s3_backup_store_spec.rb+++ b/spec/lib/backup_restore/s3_backup_store_spec.rb@@ -101,7 +101,7 @@ describe BackupRestore::S3BackupStore doprefix = 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") }enddef remove_backups