mirror of
https://codeberg.org/puppe/mpbackup.git
synced 2025-12-20 05:52:18 +01:00
Make path to restic executable configurable
This commit is contained in:
parent
84824aae02
commit
b0973f25d7
1 changed files with 14 additions and 7 deletions
21
mpbackup
21
mpbackup
|
|
@ -38,14 +38,20 @@ def unset_restic_vars
|
||||||
ENV.delete('RESTIC_CACHE_DIR')
|
ENV.delete('RESTIC_CACHE_DIR')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_restic_path(config)
|
||||||
|
if !config.key? 'restic-path'
|
||||||
|
config['restic-path'] = 'restic'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def error(exit_status, message)
|
def error(exit_status, message)
|
||||||
STDERR.puts("Error: #{message}")
|
STDERR.puts("Error: #{message}")
|
||||||
exit exit_status
|
exit exit_status
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check(config)
|
||||||
puts 'Checking restic repo …'
|
puts 'Checking restic repo …'
|
||||||
check_command = ['restic', 'check']
|
check_command = [config['restic-path'], 'check']
|
||||||
puts("Command: #{check_command.join(' ')}")
|
puts("Command: #{check_command.join(' ')}")
|
||||||
system(*check_command)
|
system(*check_command)
|
||||||
if $?.exitstatus > 0
|
if $?.exitstatus > 0
|
||||||
|
|
@ -62,20 +68,20 @@ def backup(config)
|
||||||
exclude = config.dig('backup', 'exclude')&.flat_map{|e| ['--exclude', e]} || []
|
exclude = config.dig('backup', 'exclude')&.flat_map{|e| ['--exclude', e]} || []
|
||||||
tags = config.dig('backup', 'tags')&.flat_map{|t| ['--tag', t]} || []
|
tags = config.dig('backup', 'tags')&.flat_map{|t| ['--tag', t]} || []
|
||||||
paths = config.dig('backup', 'paths') || []
|
paths = config.dig('backup', 'paths') || []
|
||||||
backup_command = ['restic', 'backup', *exclude, *paths, *flags]
|
backup_command = [config['restic-path'], 'backup', *exclude, *paths, *flags]
|
||||||
puts("Command: #{backup_command.join(' ')}")
|
puts("Command: #{backup_command.join(' ')}")
|
||||||
system(*backup_command)
|
system(*backup_command)
|
||||||
if $?.exitstatus > 0
|
if $?.exitstatus > 0
|
||||||
error(1, 'Failed to do backup.')
|
error(1, 'Failed to do backup.')
|
||||||
end
|
end
|
||||||
|
|
||||||
check
|
check(config)
|
||||||
|
|
||||||
if config.dig('forget', 'enable')
|
if config.dig('forget', 'enable')
|
||||||
puts 'Forgetting unnecessary snapshots …'
|
puts 'Forgetting unnecessary snapshots …'
|
||||||
flags = config['forget'].select{|k,v| k != 'enable'}
|
flags = config['forget'].select{|k,v| k != 'enable'}
|
||||||
flags = flags.flat_map{|k,v| ['--' + k, v.to_s]}
|
flags = flags.flat_map{|k,v| ['--' + k, v.to_s]}
|
||||||
forget_command = ['restic', 'forget'] + flags
|
forget_command = [config['restic-path'], 'forget'] + flags
|
||||||
puts("Command: #{forget_command.join(' ')}")
|
puts("Command: #{forget_command.join(' ')}")
|
||||||
system(*forget_command)
|
system(*forget_command)
|
||||||
# Data will only be deleted when `restic prune` is executed or when
|
# Data will only be deleted when `restic prune` is executed or when
|
||||||
|
|
@ -88,7 +94,7 @@ end
|
||||||
|
|
||||||
def prune(config)
|
def prune(config)
|
||||||
puts 'Pruning restic repo …'
|
puts 'Pruning restic repo …'
|
||||||
prune_command = ['restic', 'prune']
|
prune_command = [config['restic-path'], 'prune']
|
||||||
puts("Command: #{prune_command.join(' ')}")
|
puts("Command: #{prune_command.join(' ')}")
|
||||||
system(*prune_command)
|
system(*prune_command)
|
||||||
if $?.exitstatus > 0
|
if $?.exitstatus > 0
|
||||||
|
|
@ -101,12 +107,13 @@ end
|
||||||
def run_restic(config)
|
def run_restic(config)
|
||||||
puts 'Executing restic with the following arguments …'
|
puts 'Executing restic with the following arguments …'
|
||||||
puts "ARGV: #{ARGV}"
|
puts "ARGV: #{ARGV}"
|
||||||
exec('restic', *ARGV)
|
exec(config['restic-path'], *ARGV)
|
||||||
end
|
end
|
||||||
|
|
||||||
def act(config, options)
|
def act(config, options)
|
||||||
puts "Applying configuration ‘#{config['name']}’ …"
|
puts "Applying configuration ‘#{config['name']}’ …"
|
||||||
set_restic_vars(config)
|
set_restic_vars(config)
|
||||||
|
set_restic_path(config)
|
||||||
if options[:prune]
|
if options[:prune]
|
||||||
prune config
|
prune config
|
||||||
elsif options[:run_restic]
|
elsif options[:run_restic]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue