Improve text output for users

This commit is contained in:
Martin Puppe 2020-03-25 17:53:59 +01:00
parent 6388495fc7
commit ee2e4d7129

View file

@ -34,10 +34,11 @@ if !Pathname.new(config_file).exist? then
end
def do_backup(config)
puts "Applying configuration #{config['name']} …"
ENV['RESTIC_REPOSITORY'] = config['repository']
ENV['RESTIC_PASSWORD'] = STDIN.getpass('Please put in your restic password: ')
puts "Backing up with restic…"
puts "Backing up with restic …"
# https://restic.readthedocs.io/en/latest/040_backup.html#including-and-excluding-files
exclude = config.dig('backup', 'exclude')&.flat_map{|e| ['--exclude', e]} || []
paths = config.dig('backup', 'paths') || []
@ -49,7 +50,7 @@ def do_backup(config)
exit 1
end
puts 'Checking restic repo…'
puts 'Checking restic repo …'
check_command = ['restic', 'check']
puts("Command: #{check_command.join(' ')}")
system(*check_command)
@ -58,7 +59,7 @@ def do_backup(config)
exit 1
end
puts "Deleting unnecessary snapshots…"
puts "Deleting unnecessary snapshots …"
flags = config['forget'].filter{|k,v| k != 'enable'}
flags = flags.flat_map{|k,v| ['--' + k, v.to_s]}
forget_command = ['restic', 'forget'] + flags
@ -75,9 +76,11 @@ def do_backup(config)
ENV.delete('RESTIC_PASSWORD')
end
puts "Using config file #{config_file} …"
configs = YAML.load_stream(File.open(config_file))
if ARGV.empty?
puts "No configuration name has been given. Using the first configuration."
puts "No configuration name has been given. Will use the first "\
"configuration from the file (#{configs.dig(0, 'name')})."
do_backup(configs[0])
else
ARGV.each do |config_name|