DEV: Delete vacate_legacy_prefix_backups code (#14735)

DEV: Delete vacate_legacy_prefix_backups code (#14735)

Introduced in 3037617327147602d84e584c56a7d69dd001da0a, we no longer need this code, as all of the backups have been migrated.

diff --git a/app/jobs/onceoff/vacate_legacy_prefix_backups.rb b/app/jobs/onceoff/vacate_legacy_prefix_backups.rb
deleted file mode 100644
index 0791a01..0000000
--- a/app/jobs/onceoff/vacate_legacy_prefix_backups.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: true
-
-module Jobs
-  class VacateLegacyPrefixBackups < ::Jobs::Onceoff
-    def execute_onceoff(args)
-      args ||= {}
-      BackupRestore::S3BackupStore.create(s3_options: args[:s3_options]).vacate_legacy_prefix if SiteSetting.backup_location == BackupLocationSiteSetting::S3
-    end
-  end
-end
diff --git a/lib/backup_restore/s3_backup_store.rb b/lib/backup_restore/s3_backup_store.rb
index f991c05..71c3684 100644
--- a/lib/backup_restore/s3_backup_store.rb
+++ b/lib/backup_restore/s3_backup_store.rb
@@ -51,22 +51,6 @@ module BackupRestore
       raise StorageError.new(e.message.presence || e.class.name)
     end
 
-    def vacate_legacy_prefix
-      legacy_s3_helper = S3Helper.new(s3_bucket_name_with_legacy_prefix, '', @s3_options.clone)
-      bucket, prefix = s3_bucket_name_with_prefix.split('/', 2)
-      legacy_keys = legacy_s3_helper.list
-        .reject { |o| o.key.starts_with? prefix }
-        .map { |o| o.key }
-      legacy_keys.each do |legacy_key|
-        @s3_helper.s3_client.copy_object({
-          copy_source: File.join(bucket, legacy_key),
-          bucket: bucket,
-          key: File.join(prefix, legacy_key.split('/').last)
-        })
-        legacy_s3_helper.delete_object(legacy_key)
-      end
-    end
-
     private
 
     def unsorted_files
@@ -117,14 +101,6 @@ module BackupRestore
       File.join(SiteSetting.s3_backup_bucket, RailsMultisite::ConnectionManagement.current_db)
     end
 
-    def s3_bucket_name_with_legacy_prefix
-      if Rails.configuration.multisite
-        File.join(SiteSetting.s3_backup_bucket, "backups", RailsMultisite::ConnectionManagement.current_db)
-      else
-        SiteSetting.s3_backup_bucket
-      end
-    end
-
     def file_regex
       @file_regex ||= begin
         path = @s3_helper.s3_bucket_folder_path || ""
diff --git a/spec/jobs/vacate_legacy_prefix_backups_spec.rb b/spec/jobs/vacate_legacy_prefix_backups_spec.rb
deleted file mode 100644
index 45eb0df..0000000
--- a/spec/jobs/vacate_legacy_prefix_backups_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-require "s3_helper"
-require "rails_helper"
-
-describe Jobs::VacateLegacyPrefixBackups, type: :multisite do
-  let(:bucket_name) { "backupbucket" }
-
-  before do
-    @s3_client = Aws::S3::Client.new(stub_responses: true)
-    @s3_options = { client: @s3_client }
-    @objects = []
-    create_backups
-
-    @s3_client.stub_responses(:list_objects_v2, -> (context) do
-      { contents: objects_with_prefix(context) }
-    end)
-
-    setup_s3
-    SiteSetting.s3_backup_bucket = bucket_name
-    SiteSetting.backup_location = BackupLocationSiteSetting::S3
-  end
-
-  it "copies the backups from legacy path to new path" do
-    @objects.each do |object|
-      legacy_key = object[:key]
-      legacy_object = @s3_client.get_object(bucket: bucket_name, key: legacy_key)
-
-      @s3_client.expects(:copy_object).with({
-        copy_source: File.join(bucket_name, legacy_key),
-        bucket: bucket_name,
-        key: legacy_key.sub(/^backups\//, "")
-      })
-
-      @s3_client.expects(:delete_object).with(bucket: bucket_name, key: legacy_key).returns(legacy_object)
-    end
-
-    described_class.new.execute_onceoff(s3_options: @s3_options)
-  end
-
-  def objects_with_prefix(context)
-    prefix = context.params[:prefix]
-    @objects.select { |obj| obj[:key].start_with?(prefix) }
-  end
-
-  def create_backups
-    @objects.clear
-
-    @objects << { key: "backups/default/b.tar.gz", size: 17, last_modified: Time.parse("2018-09-13T15:10:00Z") }
-    @objects << { key: "backups/default/filename.tar.gz", size: 17, last_modified: Time.parse("2019-10-18T17:20:00Z") }
-  end
-end

GitHub sha: b659e94a8eb444094839df633a1a189423e42eb3

This commit appears in #14735 which was approved by CvX. It was merged by martin.