File: process.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (59 lines) | stat: -rw-r--r-- 1,568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module Backup
  module Restore
    class Process
      attr_reader :backup_id, :backup_task, :backup_path, :logger

      # Restore process class, dedicated to perform restore tasks
      #
      # @param [String] backup_id Current or previous backup ID
      # @param [Backup::Tasks::Task] backup_task Task to restore
      # @param [Pathname] backup_path Pathname of the backup
      # @param [Gitlab::BackupLogger] logger interface
      def initialize(backup_id:, backup_task:, backup_path:, logger:)
        @backup_id = backup_id
        @backup_task = backup_task
        @backup_path = backup_path
        @logger = logger
      end

      def execute!
        return unless backup_task_enabled?

        logger.info "Restoring #{backup_task.human_name} ... "

        # Pre restore
        output_warning(backup_task.pre_restore_warning)

        # Restore
        backup_task.restore!(backup_path, backup_id)

        logger.info "Restoring #{backup_task.human_name} ... done"

        # Post restore
        output_warning(backup_task.post_restore_warning)
      rescue Gitlab::TaskAbortedByUserError
        logger.error "Quitting..."

        exit 1
      end

      private

      def backup_task_enabled?
        return true if backup_task.enabled?

        logger.info "Restoring #{backup_task.human_name} ... [DISABLED]"
        false
      end

      def output_warning(warning)
        return unless warning.present?

        logger.warn warning
        Gitlab::TaskHelpers.ask_to_continue
      end
    end
  end
end