Class: Bitferry::Restic::Backup

Inherits:
Task
  • Object
show all
Defined in:
lib/bitferry.rb

Constant Summary collapse

PROCESS =
{
  default: ['--no-cache']
}
FORGET =
{
  default: ['--prune', '--no-cache', '--keep-within-hourly', '24h', '--keep-within-daily', '7d', '--keep-within-weekly', '30d', '--keep-within-monthly', '1y', '--keep-within-yearly', '100y']
}
CHECK =
{
  default: ['--no-cache'],
  full: ['--no-cache', '--read-data']
}

Constants inherited from Task

Task::ROUTE

Instance Attribute Summary collapse

Attributes inherited from Task

#directory, #repository

Attributes inherited from Task

#exclude, #generation, #include, #modified, #tag

Instance Method Summary collapse

Methods inherited from Task

#common_options, #execute, #include_filters, #initialize, #intact?, #password, #refers?, #touch

Methods inherited from Task

[], #commit, #delete, delete, #initialize, intact, live, #live?, lookup, match, new, #process_options, register, registered, reset, restore, #restore_endpoint, #show_filters, stale, #touch

Methods included from Logging

log, #log

Constructor Details

This class inherits a constructor from Bitferry::Restic::Task

Instance Attribute Details

#check_optionsObject (readonly)

Returns the value of attribute check_options.



1138
1139
1140
# File 'lib/bitferry.rb', line 1138

def check_options
  @check_options
end

#forget_optionsObject (readonly)

Returns the value of attribute forget_options.



1137
1138
1139
# File 'lib/bitferry.rb', line 1137

def forget_options
  @forget_options
end

Instance Method Details

#common_options_simulateObject



1181
# File 'lib/bitferry.rb', line 1181

def common_options_simulate = common_options + [Bitferry.simulate? ? '--dry-run' : nil].compact

#create(*args, format: nil, process: nil, forget: nil, check: nil, **opts) ⇒ Object



1141
1142
1143
1144
1145
1146
1147
# File 'lib/bitferry.rb', line 1141

def create(*args, format: nil, process: nil, forget: nil, check: nil, **opts)
  super(*args, **opts)
  @format = format
  @process_options = Bitferry.optional(process, PROCESS)
  @forget_options = Bitferry.optional(forget, FORGET)
  @check_options = Bitferry.optional(check, CHECK)
end

#exclude_filtersObject



1150
# File 'lib/bitferry.rb', line 1150

def exclude_filters = ([Volume::STORAGE, Volume::STORAGE_] + exclude).collect { |x| ['--exclude', x]}.flatten

#externalizeObject



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
# File 'lib/bitferry.rb', line 1184

def externalize
  restic = {
    process: process_options,
    forget: forget_options,
    check: check_options
  }.compact
  super.merge({
    operation: :backup,
    restic: restic.empty? ? nil : restic
  }.compact)
end

#formatObject



1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/bitferry.rb', line 1206

def format
  if Bitferry.simulate?
    log.info('skipped repository initialization (simulation)')
  else
    log.info("initializing repository for task #{tag}")
    if @format == true
      log.debug("wiping repository in #{repository.root}")
      ['config', 'data', 'index', 'keys', 'locks', 'snapshots'].each { |x| FileUtils.rm_rf(File.join(repository.root.to_s, x)) }
    end
    if @format == false
      # TODO validate existing repo
      log.info("attached to existing repository for task #{tag} in #{repository.root}")
    else
      begin
        execute(*common_options, 'init')
        log.info("initialized repository for task #{tag} in #{repository.root}")
      rescue
        log.fatal("failed to initialize repository for task #{tag} in #{repository.root}")
        raise
      end
    end
  end
  @state = :intact
end

#processObject



1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
# File 'lib/bitferry.rb', line 1162

def process
  begin
    log.info("processing task #{tag}")
    execute('backup', '.', '--tag', "bitferry,#{tag}", *exclude_filters, *process_options, *common_options_simulate, chdir: directory.root)
    unless check_options.nil?
      log.info("checking repository in #{repository.root}")
      execute('check', *check_options, *common_options)
    end
    unless forget_options.nil?
      log.info("performing repository maintenance tasks in #{repository.root}")
      execute('forget', '--tag', "bitferry,#{tag}", *forget_options.collect(&:to_s), *common_options_simulate)
    end
    true
  rescue
    false
  end
end

#restore(hash) ⇒ Object



1197
1198
1199
1200
1201
1202
1203
# File 'lib/bitferry.rb', line 1197

def restore(hash)
  super
  opts = hash.fetch(:restic, {})
  @process_options = opts[:process]
  @forget_options = opts[:forget]
  @check_options = opts[:check]
end

#show_directionObject



1159
# File 'lib/bitferry.rb', line 1159

def show_direction = '-->'

#show_operationObject



1156
# File 'lib/bitferry.rb', line 1156

def show_operation = 'encrypt+backup'

#show_statusObject



1153
# File 'lib/bitferry.rb', line 1153

def show_status = "#{show_operation} #{directory.show_status} #{show_direction} #{repository.show_status} #{show_filters}"