Class: Yobi::BackupOutcome

Inherits:
Struct
  • Object
show all
Defined in:
lib/yobi/repository/backup.rb,
sig/yobi.rbs

Overview

The outcome of one Repository#backup call.

Constant Summary collapse

COMMAND_OUTPUT_LINE_PATTERN =

Matches Restic's own log line format for stderr relayed from a source: [:stdin_from_command, ...] command's own subprocess.

Returns:

  • (Regexp)
/\Asubprocess [^:]+: (.*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exit_codeObject

Returns the value of attribute exit_code

Returns:

  • (Object)

    the current value of exit_code



123
124
125
# File 'lib/yobi/repository/backup.rb', line 123

def exit_code
  @exit_code
end

#outputObject

Returns the value of attribute output

Returns:

  • (Object)

    the current value of output



123
124
125
# File 'lib/yobi/repository/backup.rb', line 123

def output
  @output
end

Instance Method Details

#command_outputArray<String>

The source: [:stdin_from_command, ...] subprocess's own stderr, if any, de-prefixed.

Returns:

  • (Array<String>)


146
147
148
149
150
151
# File 'lib/yobi/repository/backup.rb', line 146

def command_output
  @command_output ||= output.each_line.filter_map do |line|
    match = COMMAND_OUTPUT_LINE_PATTERN.match(line)
    match[1] if match
  end
end

#errorsEnumerable<Yobi::BackupError>

Returns:



139
140
141
# File 'lib/yobi/repository/backup.rb', line 139

def errors
  @errors ||= BackupErrors.new(output)
end

#partial?Boolean

Returns true if the backup completed with some files skipped.

Returns:

  • (Boolean)

    true if the backup completed with some files skipped



134
135
136
# File 'lib/yobi/repository/backup.rb', line 134

def partial?
  exit_code == 3
end

#reportHash

Returns Restic's own "summary" fields, with "backup_start"/"backup_end" parsed into Time.

Returns:

  • (Hash)

    Restic's own "summary" fields, with "backup_start"/"backup_end" parsed into Time



154
155
156
157
158
159
160
161
162
# File 'lib/yobi/repository/backup.rb', line 154

def report
  @report ||= begin
    hash = summary_hash
    hash.merge(
      "backup_start" => (Time.parse(hash["backup_start"]) if hash["backup_start"]),
      "backup_end" => (Time.parse(hash["backup_end"]) if hash["backup_end"])
    )
  end
end

#success?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/yobi/repository/backup.rb', line 129

def success?
  exit_code.zero?
end