mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not show backups stored in subfolder of bucket
This commit is contained in:
@@ -59,7 +59,7 @@ module BackupRestore
|
|||||||
objects = []
|
objects = []
|
||||||
|
|
||||||
@s3_helper.list.each do |obj|
|
@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)
|
objects << create_file_from_object(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -106,6 +106,19 @@ module BackupRestore
|
|||||||
end
|
end
|
||||||
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
|
def free_bytes
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@@ -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: "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: "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", 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-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)
|
create_file(db_name: "second", filename: "multi-1.tar.gz", last_modified: "2018-11-26T03:17:09Z", size_in_bytes: 22)
|
||||||
|
@@ -101,7 +101,7 @@ describe BackupRestore::S3BackupStore do
|
|||||||
prefix = context.params[:prefix]
|
prefix = context.params[:prefix]
|
||||||
|
|
||||||
if prefix.blank?
|
if prefix.blank?
|
||||||
@objects.reject { |obj| obj[:key].include?("/") }
|
@objects.reject { |obj| obj[:key].include?("backups/") }
|
||||||
else
|
else
|
||||||
@objects.select { |obj| obj[:key].start_with?(prefix) }
|
@objects.select { |obj| obj[:key].start_with?(prefix) }
|
||||||
end
|
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: "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: "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: "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-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/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
|
end
|
||||||
|
|
||||||
def remove_backups
|
def remove_backups
|
||||||
|
Reference in New Issue
Block a user