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 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
# frozen_string_literal: true
module Backup
module Tasks
class Task
attr_reader :progress, :options
# Identifier used as parameter in the CLI to skip from executing
def self.id
raise NotImplementedError
end
def initialize(progress:, options:)
@progress = progress
@options = options
end
# Initiate a backup
#
# @param [Pathname] backup_path a path where to store the backups
# @param [String] backup_id
def backup!(backup_path, backup_id)
backup_output = backup_path.join(destination_path)
target.dump(backup_output, backup_id)
end
def restore!(backup_path, backup_id)
backup_output = backup_path.join(destination_path)
target.restore(backup_output, backup_id)
end
# Key string that identifies the task
def id = self.class.id
# Name of the task used for logging.
def human_name
raise NotImplementedError
end
# Where to put the backup content
# It can be either an archive file or a directory containing multiple data
def destination_path
raise NotImplementedError
end
# Path to remove after a successful backup, uses #destination_path when not specified
def cleanup_path = destination_path
# `true` if the destination might not exist on a successful backup
def destination_optional = false
# `true` if the task can be used
def enabled = true
def enabled? = enabled
# a string returned here will be displayed to the user before calling #restore
def pre_restore_warning = nil
# a string returned here will be displayed to the user after calling #restore
def post_restore_warning = nil
private
# The target factory method
def target
raise NotImplementedError
end
end
end
end
|