Class: Kitsune::Kit::Operations::ServiceBackup

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/operations/service_backup.rb

Constant Summary collapse

BACKUP_IMAGE =
"alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc"

Instance Method Summary collapse

Constructor Details

#initialize(config:, type:, transport:, compose:, clock: -> { Time.now.utc }) ⇒ ServiceBackup

Returns a new instance of ServiceBackup.



11
12
13
14
15
16
17
# File 'lib/kitsune/kit/operations/service_backup.rb', line 11

def initialize(config:, type:, transport:, compose:, clock: -> { Time.now.utc })
  @config = config
  @type = type
  @transport = transport
  @compose = compose
  @clock = clock
end

Instance Method Details

#call(state) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kitsune/kit/operations/service_backup.rb', line 19

def call(state)
  unless state&.fetch("installed", true)
    raise Errors::UnsafeOperationError.new(
      "#{type} is not installed",
      hint: "Install and verify the service before creating a data backup."
    )
  end

  directory = "/home/#{config.ssh.user}/.local/share/kitsune/backups/#{type}"
  path = "#{directory}/#{type}-#{clock.call.strftime('%Y%m%dT%H%M%S')}.tar.gz"
  create_directory(directory)
  create_archive(directory, path, state.fetch("volume"))
  path
end