Skip to content

Commit

Permalink
Update 035_valid_backup_methods.sh
Browse files Browse the repository at this point in the history
Simplified prep/default/035_valid_backup_methods.sh
to make it work more predictable and fail-safe, cf.
#2353 (comment)
  • Loading branch information
jsmeix committed Mar 31, 2020
1 parent bdff9e0 commit e98c8ad
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions usr/share/rear/prep/default/035_valid_backup_methods.sh
@@ -1,28 +1,16 @@

# For "rear mkbackup" and also for "rear mkrescue" (also the latter
# because for most external backup methods only "rear mkrescue" is used)
# check what BACKUP methods are mentioned in the form BACKUP=method in default.conf
# and error out when a BACKUP method is not found this way in default.conf
# For "rear mkbackup" and also for "rear mkrescue"
# ( also the latter because for most external backup methods only "rear mkrescue"
# is used because most external backup methods do not implement making a backup
# but only implement to restore a backup see 'BACKUP SOFTWARE INTEGRATION' in "man rear" )
# check that the BACKUP method implements a matching backup restore method
# i.e. check that a usr/share/rear/restore/$BACKUP directory exists
# and error out when a BACKUP method seems to not support a backup restore
# to ensure that the user cannot specify a non-working BACKUP in /etc/rear/local.conf
# and to ensure that each implemented BACKUP method is mentioned in default.conf
# to have a minimum documentation about what BACKUP methods are implemented in ReaR
# see https://github.com/rear/rear/issues/914
# and https://github.com/rear/rear/issues/159
# and https://github.com/rear/rear/issues/2337#issuecomment-596471615

local backup_method
local valid_backup_methods=()

# That 'grep|cut|awk' pipe may find more words than actually valid backup methods
# e.g. assume default.conf contains "using BACKUP=QQQ does not work"
# and it may not find an actually valid backup method
# e.g. assume a valid backup method FOO is only mentioned as "use BACKUP=FOO with BACKUP_URL"
# so a more fail-safe method to autodetect actually valid backup methods may be needed in the future:
for backup_method in $( grep 'BACKUP=' $SHARE_DIR/conf/default.conf | grep -v '_' | cut -d= -f2 | awk '{print $1}' | sort -u ) ; do
valid_backup_methods+=( "$backup_method" )
done

if ! grep -q "$BACKUP" <<< $( echo ${valid_backup_methods[@]} ) ; then
Error "The BACKUP method '$BACKUP' is not known to ReaR."
if ! test -d "$SHARE_DIR/restore/$BACKUP" ; then
Error "The BACKUP method '$BACKUP' is not supported (no $SHARE_DIR/restore/$BACKUP directory)"
fi

2 comments on commit e98c8ad

@jsmeix
Copy link
Member Author

@jsmeix jsmeix commented on e98c8ad Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit fixes
#2352

@jsmeix
Copy link
Member Author

@jsmeix jsmeix commented on e98c8ad Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thic commit is a precondition for the fix of
#2351

Please sign in to comment.