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
#generation, #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, stale
Methods included from Logging
log, #log
Constructor Details
#initialize(directory, repository, **opts) ⇒ Task
Returns a new instance of Task.
985
986
987
988
989
|
# File 'lib/bitferry.rb', line 985
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.
982
983
984
|
# File 'lib/bitferry.rb', line 982
def directory
@directory
end
|
#repository ⇒ Object
Returns the value of attribute repository.
982
983
984
|
# File 'lib/bitferry.rb', line 982
def repository
@repository
end
|
Instance Method Details
#common_options ⇒ Object
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
|
# File 'lib/bitferry.rb', line 1016
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
992
993
994
995
996
|
# File 'lib/bitferry.rb', line 992
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
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
# File 'lib/bitferry.rb', line 1028
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 "restic exit code #{status.exitstatus}" unless status.success?
ensure
Dir.chdir(wd) unless chdir.nil?
end
end
end
|
#externalize ⇒ Object
1050
1051
1052
1053
1054
1055
|
# File 'lib/bitferry.rb', line 1050
def externalize
super.merge(
directory: directory.externalize,
repository: repository.externalize,
).compact
end
|
1013
|
# File 'lib/bitferry.rb', line 1013
def format = nil
|
#intact? ⇒ Boolean
1002
|
# File 'lib/bitferry.rb', line 1002
def intact? = live? && directory.intact? && repository.intact?
|
#password ⇒ Object
999
|
# File 'lib/bitferry.rb', line 999
def password = @password ||= Rclone.reveal(Volume[directory.volume_tag].vault.fetch(tag))
|
#refers?(volume) ⇒ Boolean
1005
|
# File 'lib/bitferry.rb', line 1005
def refers?(volume) = directory.refers?(volume) || repository.refers?(volume)
|
#restore(hash) ⇒ Object
1058
1059
1060
1061
1062
1063
1064
1065
1066
|
# File 'lib/bitferry.rb', line 1058
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
1008
1009
1010
1011
|
# File 'lib/bitferry.rb', line 1008
def touch
@generation = [directory.generation, repository.generation].max + 1
super
end
|