From 0d98802d8a43a92d0e41ce591360f67b94a4e008 Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Thu, 4 Mar 2021 09:31:29 +0100 Subject: [PATCH 1/4] Add support for specifying tags for backups --- mpbackup | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mpbackup b/mpbackup index 57a7449..aba9d47 100644 --- a/mpbackup +++ b/mpbackup @@ -62,9 +62,11 @@ end def backup(config) puts "Backing up with restic …" # https://restic.readthedocs.io/en/latest/040_backup.html#including-and-excluding-files - flags = config['backup'].select{|k,v| k != 'exclude' && k != 'paths'} + flags = config['backup'].select{|k,v| + k != 'exclude' && k != 'paths' && k != 'tags'} flags = flags.map{|k,v| "--#{k}=#{v.to_s}"} exclude = config.dig('backup', 'exclude')&.flat_map{|e| ['--exclude', e]} || [] + tags = config.dig('backup', 'tags')&.flat_map{|t| ['--tag', t]} || [] paths = config.dig('backup', 'paths') || [] backup_command = ['restic', 'backup', *exclude, *paths, *flags] puts("Command: #{backup_command.join(' ')}") From 84824aae02d13862d908b6f55a547a5e9d6a8bb1 Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Fri, 5 Mar 2021 14:56:29 +0100 Subject: [PATCH 2/4] Replace config option cache-home with cache-dir --- mpbackup | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mpbackup b/mpbackup index aba9d47..4e70eb0 100644 --- a/mpbackup +++ b/mpbackup @@ -8,8 +8,6 @@ DEFAULT_CONFIG_FILE = Pathname.new('/etc/mpbackup/config.yaml') NAME = 'mpbackup' VERSION = '0.5.0' -$original_cache_home = ENV['XDG_CACHE_HOME'] - def set_restic_vars(config) if config['repository-file'] puts "Reading repository from file #{config['repository-file']} …" @@ -25,9 +23,9 @@ def set_restic_vars(config) else password = STDIN.getpass('Please put in your restic password: ') end - if config['cache-home'] - puts "Setting XDG_CACHE_HOME to #{config['cache-home']} …" - ENV['XDG_CACHE_HOME'] = config['cache-home'] + if config['cache-dir'] + puts "Setting RESTIC_CACHE_DIR to #{config['cache-dir']} …" + ENV['RESTIC_CACHE_DIR'] = config['cache-dir'] end ENV['RESTIC_REPOSITORY'] = repo @@ -37,11 +35,7 @@ end def unset_restic_vars ENV.delete('RESTIC_REPOSITORY') ENV.delete('RESTIC_PASSWORD') - if $original_cache_home - ENV['XDG_CACHE_HOME'] = $original_cache_home - else - ENV.delete('XDG_CACHE_HOME') - end + ENV.delete('RESTIC_CACHE_DIR') end def error(exit_status, message) From b0973f25d74e90872800bf629c65fdb665f8e37d Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Sat, 6 Mar 2021 16:13:34 +0100 Subject: [PATCH 3/4] Make path to restic executable configurable --- mpbackup | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mpbackup b/mpbackup index 4e70eb0..1935947 100644 --- a/mpbackup +++ b/mpbackup @@ -38,14 +38,20 @@ def unset_restic_vars ENV.delete('RESTIC_CACHE_DIR') end +def set_restic_path(config) + if !config.key? 'restic-path' + config['restic-path'] = 'restic' + end +end + def error(exit_status, message) STDERR.puts("Error: #{message}") exit exit_status end -def check +def check(config) puts 'Checking restic repo …' - check_command = ['restic', 'check'] + check_command = [config['restic-path'], 'check'] puts("Command: #{check_command.join(' ')}") system(*check_command) if $?.exitstatus > 0 @@ -62,20 +68,20 @@ def backup(config) exclude = config.dig('backup', 'exclude')&.flat_map{|e| ['--exclude', e]} || [] tags = config.dig('backup', 'tags')&.flat_map{|t| ['--tag', t]} || [] 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(' ')}") system(*backup_command) if $?.exitstatus > 0 error(1, 'Failed to do backup.') end - check + check(config) if config.dig('forget', 'enable') puts 'Forgetting unnecessary snapshots …' flags = config['forget'].select{|k,v| k != 'enable'} 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(' ')}") system(*forget_command) # Data will only be deleted when `restic prune` is executed or when @@ -88,7 +94,7 @@ end def prune(config) puts 'Pruning restic repo …' - prune_command = ['restic', 'prune'] + prune_command = [config['restic-path'], 'prune'] puts("Command: #{prune_command.join(' ')}") system(*prune_command) if $?.exitstatus > 0 @@ -101,12 +107,13 @@ end def run_restic(config) puts 'Executing restic with the following arguments …' puts "ARGV: #{ARGV}" - exec('restic', *ARGV) + exec(config['restic-path'], *ARGV) end def act(config, options) puts "Applying configuration ‘#{config['name']}’ …" set_restic_vars(config) + set_restic_path(config) if options[:prune] prune config elsif options[:run_restic] From cfba3f37c50dde899ffa0c1d6a81d0f15ed29911 Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Sat, 6 Mar 2021 16:14:40 +0100 Subject: [PATCH 4/4] Version 0.5.0 -> 0.6.0 --- mpbackup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpbackup b/mpbackup index 1935947..594526b 100644 --- a/mpbackup +++ b/mpbackup @@ -6,7 +6,7 @@ require 'yaml' DEFAULT_CONFIG_FILE = Pathname.new('/etc/mpbackup/config.yaml') NAME = 'mpbackup' -VERSION = '0.5.0' +VERSION = '0.6.0' def set_restic_vars(config) if config['repository-file']