Class: Bitferry::Restic::Task
- Inherits:
-
Task
- Object
- Task
- Bitferry::Restic::Task
show all
- Defined in:
- lib/bitferry.rb
Constant Summary
Constants inherited
from Task
Task::ROUTE
Instance Attribute Summary collapse
Attributes inherited from Task
#exclude, #generation, #include, #modified, #tag
Instance Method Summary
collapse
Methods inherited from Task
[], #commit, #delete, delete, intact, live, #live?, lookup, match, new, #process_options, register, registered, reset, restore, #restore_endpoint, #show_filters, stale
Methods included from Logging
log, #log
Constructor Details
#initialize(directory, repository, **opts) ⇒ Task
Returns a new instance of Task.
1023
1024
1025
1026
1027
|
# File 'lib/bitferry.rb', line 1023
def initialize(directory, repository, **opts)
super(**opts)
@directory = directory.is_a?(Endpoint) ? directory : Bitferry.endpoint(directory)
@repository = repository.is_a?(Endpoint) ? repository : Bitferry.endpoint(repository)
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
1020
1021
1022
|
# File 'lib/bitferry.rb', line 1020
def directory
@directory
end
|
#repository ⇒ Object
Returns the value of attribute repository.
1020
1021
1022
|
# File 'lib/bitferry.rb', line 1020
def repository
@repository
end
|
Instance Method Details
#common_options ⇒ Object
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
# File 'lib/bitferry.rb', line 1058
def common_options
[
case Bitferry.verbosity
when :verbose then '--verbose'
when :quiet then '--quiet'
else nil
end,
'-r', repository.root.to_s
].compact
end
|
#create(directory, repository, password, **opts) ⇒ Object
1030
1031
1032
1033
1034
|
# File 'lib/bitferry.rb', line 1030
def create(directory, repository, password, **opts)
super(directory, repository, **opts)
raise TypeError, 'unsupported unencrypted endpoint type' unless self.directory.is_a?(Endpoint::Bitferry)
Volume[self.directory.volume_tag].vault[tag] = Rclone.obscure(@password = password) end
|
#execute(*args, simulate: false, chdir: nil) ⇒ Object
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
# File 'lib/bitferry.rb', line 1070
def execute(*args, simulate: false, chdir: nil)
cmd = [Restic.executable] + args
ENV['RESTIC_PASSWORD'] = password
cms = cmd.collect(&:shellescape).join(' ')
puts cms if Bitferry.verbosity == :verbose
log.info(cms)
if simulate
log.info('(simulated)')
true
else
wd = Dir.getwd unless chdir.nil?
begin
Dir.chdir(chdir) unless chdir.nil?
status = Open3.pipeline(cmd).first
raise RuntimeError, "restic exit code #{status.exitstatus}" unless status.success?
status.success?
ensure
Dir.chdir(wd) unless chdir.nil?
end
end
end
|
#externalize ⇒ Object
1093
1094
1095
1096
1097
1098
|
# File 'lib/bitferry.rb', line 1093
def externalize
super.merge(
directory: directory.externalize,
repository: repository.externalize,
).compact
end
|
1052
|
# File 'lib/bitferry.rb', line 1052
def format = nil
|
#include_filters ⇒ Object
1055
|
# File 'lib/bitferry.rb', line 1055
def include_filters = include.collect { |x| ['--include', x]}.flatten
|
#intact? ⇒ Boolean
1040
|
# File 'lib/bitferry.rb', line 1040
def intact? = live? && directory.intact? && repository.intact?
|
#password ⇒ Object
1037
|
# File 'lib/bitferry.rb', line 1037
def password = @password ||= Rclone.reveal(Volume[directory.volume_tag].vault.fetch(tag))
|
#refers?(volume) ⇒ Boolean
1043
|
# File 'lib/bitferry.rb', line 1043
def refers?(volume) = directory.refers?(volume) || repository.refers?(volume)
|
#restore(hash) ⇒ Object
1101
1102
1103
1104
1105
1106
1107
1108
1109
|
# File 'lib/bitferry.rb', line 1101
def restore(hash)
initialize(
restore_endpoint(hash.fetch(:directory)),
restore_endpoint(hash.fetch(:repository)),
tag: hash.fetch(:task),
modified: hash.fetch(:modified, DateTime.now)
)
super(hash)
end
|
#touch ⇒ Object
1046
1047
1048
1049
|
# File 'lib/bitferry.rb', line 1046
def touch
@generation = [directory.generation, repository.generation].max + 1
super
end
|