New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BACKUP_PROG_OPTIONS used to be a string variable, turn it into an array #1475
Conversation
…ay (GD, 06/SEP/2017 - issue #1175) added new script prep/NETFS/GNU/Linux/205_inspect_tar_capabilities.sh which will automatically add capabilities to the BACKUP_PROG_OPTIONS array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice improvement, thanks a lot.
|
||
if [[ "$(basename $BACKUP_PROG)" = "tar" ]] ; then | ||
# Verify extended attributes being present: | ||
if tar --usage | grep -q "\-\-xattrs" ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO tar --usage | grep -- --xattrs
is easier to read (or quote the search term to make it even more visible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlomo thanks for the tip.
# Verify extended attributes being present: | ||
if tar --usage | grep -q "\-\-xattrs" ; then | ||
BACKUP_PROG_OPTIONS=( "${BACKUP_PROG_OPTIONS[@]}" "--xattrs" ) | ||
PROGS=( "${PROGS[@]}" getfattr setfattr ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does tar
require the setfattr
programs to restore the archive with xattrs? Or this this more for the convenience of the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlomo well it is always better to be as complete as possible. You never know.
@@ -43,7 +43,7 @@ case $(basename $BACKUP_PROG) in | |||
(tar) | |||
if tar --usage | grep -q selinux ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth to extract this into a function, it appears several times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlomo Indeed might be a good idea to do that
@@ -503,7 +503,8 @@ BACKUP_PROG_WARN_PARTIAL_TRANSFER=1 | |||
# then you also have to set the CREATE and RESTORE archive options. They are *ignored* if the | |||
# backup program is supported. | |||
# default setting for BACKUP_PROG_OPTIONS="" became "--anchored" (GD, 02/DEC/2014 - issue #475) | |||
BACKUP_PROG_OPTIONS="--anchored" | |||
# BACKUP_PROG_OPTIONS used to be a string variable, turn it into an array (GD, 06/SEP/2017 - issue #1175) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change so that we should mention it in the release notes with an explanation of what users have to adjust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlomo Yes that is the plan!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlomo # BACKUP_PROG_OPTIONS="--this --that" # echo "${BACKUP_PROG_OPTIONS[@]}" --this --that and also for adding more array elements # BACKUP_PROG_OPTIONS="--this --that" # BACKUP_PROG_OPTIONS=( "${BACKUP_PROG_OPTIONS[@]}" "--xattrs" ) # echo "${BACKUP_PROG_OPTIONS[@]}" --this --that --xattrs so that for users who specify BACKUP_PROG_OPTIONS |
It looks as if this pull request already implements |
@jsmeix please use $ v="hello world" ; declare -p v ; v=( "${v[@]}" yes we can) ; declare -p v
declare -- v="hello world"
declare -a v=([0]="hello world" [1]="yes" [2]="we" [3]="can") We can see how the initial value that consists of two words is now a single value with two words. The root cause is that we now quote the array variable whereas the previous implementation on purpose did not quote it. This is actually the core of the breaking change: |
Good grief! # set -x # opts="-i -s" + opts='-i -s' # echo 'Hello World' | grep $opts 'hello' | cat -n + grep -i -s hello + echo 'Hello World' + cat -n 1 Hello World # opts=( "${opts[@]}" "-o" ) + opts=("${opts[@]}" "-o") # echo 'Hello World' | grep "${opts[@]}" 'hello' | cat -n + grep '-i -s' -o hello + echo 'Hello World' + cat -n grep: invalid option -- ' ' Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. # echo 'Hello World' | grep ${opts[*]} 'hello' | cat -n + grep -i -s -o hello + echo 'Hello World' + cat -n 1 Hello |
Let's just try to keep unquoted arrays like |
@gdha ${BACKUP_PROG_OPTIONS[*]} in the backup restore command pipe dd if=$restore_input | $BACKUP_PROG_DECRYPT_OPTIONS $BACKUP_PROG_CRYPT_KEY | $BACKUP_PROG --block-number --totals --verbose ${BACKUP_PROG_OPTIONS[*]} "${BACKUP_PROG_COMPRESS_OPTIONS[@]}" -C $TARGET_FS_ROOT/ -x -f - could make it behave still backward compatible BACKUP_PROG_OPTIONS="--this --that" with each word as a separated array element |
I am against unquoted arrays for the sake of backwards compatibility. In general I want ReaR to look forward more than backward. That means that we should guide users in their upgrade process without compromising on the new functionality. Specifically, I can imagine adding a test that occurs after reading the user configuration. This test would check for blanks in Error "The BACKUP_PROG_OPTIONS variable is now a Bash array and not a string. Please update your configuration to look like this:${IFS}BACKUP_PROG_OPTIONS+=( $BACKUP_PROG_OPTIONS )" Example:
This will actually put the old - bad - options there and how how to write it 😄 |
Only a quick unpolished proposal how we might import # BACKUP_PROG_OPTIONS="--this --that" # old_backup_prog_options="$BACKUP_PROG_OPTIONS" # unset BACKUP_PROG_OPTIONS # for backup_prog_option in $old_backup_prog_options ; do BACKUP_PROG_OPTIONS=( "${BACKUP_PROG_OPTIONS[@]}" "$backup_prog_option" ) ; done # for backup_prog_option in "${BACKUP_PROG_OPTIONS[@]}" ; do echo $backup_prog_option ; done --this --that With some additional testing via "declare -p" whether or not |
@schlomo |
I also initially thought about an automatic migration but favor the Error message to make the whole topic more explicit and to get our users to actually update their configuration. |
In general I would prefer a test using 'declare -p' VAR=( "first value" "second value" ) i.e. already an array where the first element intentionally BACKUP_PROG_OPTIONS=( '--suffix="my suffix"' ) or some other unexpected special things like that ;-) |
Actually For the sake of simplicity I would therefore keep the test simple and trust that the actual backup will die complaining about strange options. So in any case, our test for the old form is just a courtesy to the user. |
@gdha maybe you just merge and continue? |
@schlomo I like the Error bail-out : +1
If I understand it well we check if the variable (string) contains a blank and if the amount of values in the array is 1 we have a mismatch, right? |
Yes, good point. If there are two array values and the first one has a blank then it might be intentional. [[ ${#BACKUP_PROG_OPTIONS[@]} -eq 1 && "$BACKUP_PROG_OPTIONS" == *\ * ]] && Error "..." should work just fine. No external program calls and positive logic 😄 |
…ities.sh to analyse config files; saved the BACKUP_PROG_OPTIONS array to the rescue.conf file; commented block in 400_restore_backup.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good.
|
||
# save the BACKUP_PROG_OPTIONS array content to the $ROOTFS_DIR/etc/rear/rescue.conf | ||
# we need that for the restore part with tar | ||
echo "BACKUP_PROG_OPTIONS=( ${BACKUP_PROG_OPTIONS[@]} )" >> $ROOTFS_DIR/etc/rear/rescue.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest marking BACKUP_PROG_OPTIONS
to be readonly so that nobody would accidentally modify it. Such a modification after this point would be in the rescue system.
Alternative approach would be storing these options together with the backup and not with the rescue system. One one hand they have a strong coupling to the backup archive and the stuff that it contains. On the other hand of course they depend on a certain minimum tar / rsync version and thus have a coupling with the rescue system.
|
||
# As we will only inspect 'tar' we make one big if block: | ||
|
||
if [[ "$(basename $BACKUP_PROG)" = "tar" ]] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess @jsmeix would suggest here to check for tar or return out of this script instead.
@gdha echo "BACKUP_PROG_OPTIONS=( ${BACKUP_PROG_OPTIONS[@]} )" >> $ROOTFS_DIR/etc/rear/rescue.conf which fails if a BACKUP_PROG_OPTIONS array element # arr=( 'first' 'second=foo.bar' 'the end' ) # for e in "${arr[@]}" ; do echo "'$e'" ; done 'first' 'second=foo.bar' 'the end' # echo "arr=( ${arr[@]} )" arr=( first second=foo.bar the end ) # arr=( first second=foo.bar the end ) # for e in "${arr[@]}" ; do echo "'$e'" ; done 'first' 'second=foo.bar' 'the' 'end' What seems to work for me is: # arr=( 'first' 'second=foo.bar' 'the end' ) # echo "arr=( $( for e in "${arr[@]}" ; do echo -n "'$e' " ; done ) )" arr=( 'first' 'second=foo.bar' 'the end' ) It looks rather complicated but currently I don't know |
|
Somewhere in the ReaR code I noticed a comment At least on my SLES11 machine it seems to work # unset arr # arr=( 'first' '--second=foo.bar' 'the end' ) # for e in "${arr[@]}" ; do echo "'$e'" ; done 'first' '--second=foo.bar' 'the end' # declare -p arr declare -a arr='([0]="first" [1]="--second=foo.bar" [2]="the end")' # declare -a arr='([0]="first" [1]="--second=foo.bar" [2]="the end")' # for e in "${arr[@]}" ; do echo "'$e'" ; done 'first' '--second=foo.bar' 'the end' |
I found the comment about 'declare' in an older ReaR version # store all NETFS* variables # I don't know why it does not work with the full declare -- var=value syntax # found out by experiment that I need to remove the declare -- stuff. declare -p ${!NETFS*} | sed -e 's/declare .. //' >>$ROOTFS_DIR/etc/rear/rescue.conf and according to |
It might be related to Bash 2.x, not sure any more. If I wrote it then for sure I observed that behavior somewhere. Maybe we should add some test code to our |
For me on SLES11 'declare -p' also seems to # unset var # var=" this and that " # echo "'$var'" ' this and that ' # declare -p var declare -- var=" this and that " # declare -- var=" this and that " # echo "'$var'" ' this and that ' |
@gdha see BACKUP_PROG_OPTIONS=( '--suffix="my suffix"' ) |
@jsmeix I was referring to |
👍 for keeping it simple and sticking to problems that we know from reality. That said, if we can use a Bash feature vs. self-coding then I would expect that to reduce the risk for bugs. |
I am referring to a real tar option and not to hypothetical cases. # mkdir foo # echo Hello >foo/hello # tar -cvf foo.tar foo foo/ foo/hello # tar -xv --suffix="my suffix" -f foo.tar foo/ foo/hello Renaming `foo/hello' to `foo/hellomy suffix' # find foo foo foo/hello foo/hellomy suffix |
BACKUP_PROG_OPTIONS used to be a string variable, turn it into an array (GD, 06/SEP/2017 - issue #1175)
added new script prep/NETFS/GNU/Linux/205_inspect_tar_capabilities.sh which will automatically add capabilities to the BACKUP_PROG_OPTIONS array