mirror of
https://codeberg.org/puppe/mpbackup.git
synced 2025-12-20 05:52:18 +01:00
Compare commits
No commits in common. "master" and "v0.4.0" have entirely different histories.
2 changed files with 10 additions and 25 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use nix
|
||||
34
mpbackup
34
mpbackup
|
|
@ -6,7 +6,7 @@ require 'yaml'
|
|||
|
||||
DEFAULT_CONFIG_FILE = Pathname.new('/etc/mpbackup/config.yaml')
|
||||
NAME = 'mpbackup'
|
||||
VERSION = '0.6.0'
|
||||
VERSION = '0.4.0'
|
||||
|
||||
def set_restic_vars(config)
|
||||
if config['repository-file']
|
||||
|
|
@ -23,10 +23,6 @@ def set_restic_vars(config)
|
|||
else
|
||||
password = STDIN.getpass('Please put in your restic password: ')
|
||||
end
|
||||
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
|
||||
ENV['RESTIC_PASSWORD'] = password
|
||||
|
|
@ -35,13 +31,6 @@ end
|
|||
def unset_restic_vars
|
||||
ENV.delete('RESTIC_REPOSITORY')
|
||||
ENV.delete('RESTIC_PASSWORD')
|
||||
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)
|
||||
|
|
@ -49,39 +38,35 @@ def error(exit_status, message)
|
|||
exit exit_status
|
||||
end
|
||||
|
||||
def check(config)
|
||||
def check
|
||||
puts 'Checking restic repo …'
|
||||
check_command = [config['restic-path'], 'check']
|
||||
check_command = ['restic', 'check']
|
||||
puts("Command: #{check_command.join(' ')}")
|
||||
system(*check_command)
|
||||
if $?.exitstatus > 0
|
||||
error(1, "Checking restic repository failed.")
|
||||
error(1, "Checking restic repository #{ENV['RESTIC_REPOSITORY']} failed.")
|
||||
end
|
||||
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' && 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 = [config['restic-path'], 'backup', *exclude, *paths, *flags]
|
||||
backup_command = ['restic', 'backup', *exclude, *paths]
|
||||
puts("Command: #{backup_command.join(' ')}")
|
||||
system(*backup_command)
|
||||
if $?.exitstatus > 0
|
||||
error(1, 'Failed to do backup.')
|
||||
end
|
||||
|
||||
check(config)
|
||||
check
|
||||
|
||||
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 = [config['restic-path'], 'forget'] + flags
|
||||
forget_command = ['restic', 'forget'] + flags
|
||||
puts("Command: #{forget_command.join(' ')}")
|
||||
system(*forget_command)
|
||||
# Data will only be deleted when `restic prune` is executed or when
|
||||
|
|
@ -94,7 +79,7 @@ end
|
|||
|
||||
def prune(config)
|
||||
puts 'Pruning restic repo …'
|
||||
prune_command = [config['restic-path'], 'prune']
|
||||
prune_command = ['restic', 'prune']
|
||||
puts("Command: #{prune_command.join(' ')}")
|
||||
system(*prune_command)
|
||||
if $?.exitstatus > 0
|
||||
|
|
@ -107,13 +92,12 @@ end
|
|||
def run_restic(config)
|
||||
puts 'Executing restic with the following arguments …'
|
||||
puts "ARGV: #{ARGV}"
|
||||
exec(config['restic-path'], *ARGV)
|
||||
exec('restic', *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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue