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, log=
Constructor Details
#initialize(directory, repository, **opts) ⇒ Task
Returns a new instance of Task.
1083
1084
1085
1086
1087
|
# File 'lib/bitferry.rb', line 1083
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.
1080
1081
1082
|
# File 'lib/bitferry.rb', line 1080
def directory
@directory
end
|
#repository ⇒ Object
Returns the value of attribute repository.
1080
1081
1082
|
# File 'lib/bitferry.rb', line 1080
def repository
@repository
end
|
Instance Method Details
#common_options ⇒ Object
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
# File 'lib/bitferry.rb', line 1118
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
1090
1091
1092
1093
1094
|
# File 'lib/bitferry.rb', line 1090
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
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
|
# File 'lib/bitferry.rb', line 1130
def execute(*args, simulate: false, chdir: nil)
cmd = [Restic.executable] + args
ENV['RESTIC_PASSWORD'] = password
ENV['RESTIC_PROGRESS_FPS'] = 1.to_s if Bitferry.verbosity == :verbose && Bitferry.ui == :gui
cms = cmd.collect(&:shellescape).join(' ')
$stdout.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?
if Bitferry.ui == :gui
t = nil
Open3.popen2e(*cmd) do |i, oe, thr|
while x = oe.gets; $stdout.puts(x) end
t = thr
end
status = t.value
else
status = Open3.pipeline(cmd).first
end
raise RuntimeError, "restic exit code #{status.exitstatus}" unless status.success?
status.success?
ensure
Dir.chdir(wd) unless chdir.nil?
end
end
end
|
#externalize ⇒ Object
1163
1164
1165
1166
1167
1168
|
# File 'lib/bitferry.rb', line 1163
def externalize
super.merge(
directory: directory.externalize,
repository: repository.externalize,
).compact
end
|
1112
|
# File 'lib/bitferry.rb', line 1112
def format = nil
|
#include_filters ⇒ Object
1115
|
# File 'lib/bitferry.rb', line 1115
def include_filters = include.collect { |x| ['--include', x]}.flatten
|
#intact? ⇒ Boolean
1100
|
# File 'lib/bitferry.rb', line 1100
def intact? = live? && directory.intact? && repository.intact?
|
#password ⇒ Object
1097
|
# File 'lib/bitferry.rb', line 1097
def password = @password ||= Rclone.reveal(Volume[directory.volume_tag].vault.fetch(tag))
|
#refers?(volume) ⇒ Boolean
1103
|
# File 'lib/bitferry.rb', line 1103
def refers?(volume) = directory.refers?(volume) || repository.refers?(volume)
|
#restore(hash) ⇒ Object
1171
1172
1173
1174
1175
1176
1177
1178
1179
|
# File 'lib/bitferry.rb', line 1171
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
1106
1107
1108
1109
|
# File 'lib/bitferry.rb', line 1106
def touch
@generation = [directory.generation, repository.generation].max + 1
super
end
|