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.
982
983
984
985
986
|
# File 'lib/bitferry.rb', line 982
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.
979
980
981
|
# File 'lib/bitferry.rb', line 979
def directory
@directory
end
|
#repository ⇒ Object
Returns the value of attribute repository.
979
980
981
|
# File 'lib/bitferry.rb', line 979
def repository
@repository
end
|
Instance Method Details
#common_options ⇒ Object
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
# File 'lib/bitferry.rb', line 1014
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
989
990
991
992
993
|
# File 'lib/bitferry.rb', line 989
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
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
|
# File 'lib/bitferry.rb', line 1026
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
1048
1049
1050
1051
1052
1053
|
# File 'lib/bitferry.rb', line 1048
def externalize
super.merge(
directory: directory.externalize,
repository: repository.externalize,
).compact
end
|
1011
|
# File 'lib/bitferry.rb', line 1011
def format = nil
|
#intact? ⇒ Boolean
999
|
# File 'lib/bitferry.rb', line 999
def intact? = live? && directory.intact? && repository.intact?
|
#password ⇒ Object
996
|
# File 'lib/bitferry.rb', line 996
def password = @password ||= Rclone.reveal(Volume[directory.volume_tag].vault.fetch(tag))
|
#refers?(volume) ⇒ Boolean
1002
|
# File 'lib/bitferry.rb', line 1002
def refers?(volume) = directory.refers?(volume) || repository.refers?(volume)
|
#restore(hash) ⇒ Object
1056
1057
1058
1059
1060
1061
1062
1063
1064
|
# File 'lib/bitferry.rb', line 1056
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
1005
1006
1007
1008
|
# File 'lib/bitferry.rb', line 1005
def touch
@generation = [directory.generation, repository.generation].max + 1
super
end
|