#793687 rsnapshot incorrectly handles quotes in per-backup rsync_long_args option

Package:
rsnapshot
Source:
rsnapshot
Submitter:
Dmitriy Matrosov
Date:
2022-06-18 11:39:03 UTC
Severity:
normal
Tags:
#793687#5
Date:
2015-07-26 15:22:54 UTC
From:
To:
Hi.

rsnapshot from Jessie incorrectly handles quotes in per-backup
'+rsync_long_args' option (in wheezy it works fine) - it does not remove them.
Though, quotes are required, if e.g. i want to add per-backup '--filter'
option.

How to reproduce:
1. Build..

    $ git checkout debian/1.3.1-4
    Previous HEAD position was 773afb8... Enable GNU cp and document stop_on_stale_lockfile option
    HEAD is now at 324f3d7... Bump to Standards-Version 3.9.4, change Vcs-{Git,Browse} and avoid rsnapshot-HOWTO.en.html duplication

    $ quilt push -a
    Applying patch debian/patches/01_rsnapshot_conf.diff
    patching file rsnapshot.conf.default.in
    patching file rsnapshot-program.pl
    patching file rsnapshot-program.pl

    Applying patch debian/patches/03_pod_missing_back.diff
    patching file rsnapshot-program.pl

    Applying patch debian/patches/05_backup_pgsql.diff
    patching file utils/backup_pgsql.sh

    Applying patch debian/patches/06_fix_random_file_verify.diff
    patching file utils/random_file_verify.sh

    Applying patch debian/patches/08_manpage_hourly_to_daily.diff
    patching file rsnapshot-program.pl

    Applying patch debian/patches/09_strip_backtick.diff
    patching file rsnapshot-program.pl

    Applying patch debian/patches/10_space_destdir.diff
    patching file rsnapshot-program.pl

    Applying patch debian/patches/11_lvm_snapshots.diff
    patching file rsnapshot.conf.default.in
    Hunk #2 succeeded at 202 (offset 6 lines).
    Hunk #3 succeeded at 235 (offset 6 lines).
    patching file configure.ac

    Applying patch debian/patches/12_include_conf_with_arguments.diff
    patching file rsnapshot-program.pl

    Applying patch debian/patches/13_print_warn.diff
    patching file rsnapshot-program.pl

    Now at patch debian/patches/13_print_warn.diff

    $ ./configure
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking whether make sets $(MAKE)... (cached) yes
    checking for a BSD-compatible install... /usr/bin/install -c
    checking for perl... /usr/bin/perl
    checking for rsync... /usr/bin/rsync
    checking for cp... /bin/cp
    checking for rm... /bin/rm
    checking for ssh... /usr/bin/ssh
    checking for logger... /usr/bin/logger
    checking for du... /usr/bin/du
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating rsnapshot
    config.status: creating rsnapshot-diff
    config.status: creating rsnapshot.conf.default
    config.status: creating t/support/etc/configtest.conf
    config.status: creating t/support/etc/rsync.conf
    config.status: creating t/support/etc/gnu_cp.conf
    config.status: creating t/support/etc/relative_delete_bugfix.conf
    config.status: creating t/configtest.t
    config.status: creating t/rsync.t
    config.status: creating t/gnu_cp.t
    config.status: creating t/relative_delete_bugfix.t

    Now type  "make test"    to run the regression test suite.
    Then type "make install" to install the program.

    After rsnapshot is installed, don't forget to copy
    /usr/local/etc/rsnapshot.conf.default to /usr/local/etc/rsnapshot.conf

    $ make
    cd . && /bin/bash /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/missing --run aclocal-1.9
    /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/missing: line 52: aclocal-1.9: command not found
    WARNING: `aclocal-1.9' is missing on your system.  You should only need it if
	     you modified `acinclude.m4' or `configure.ac'.  You might want
	     to install the `Automake' and `Perl' packages.  Grab them from
	     any GNU archive site.
     cd . && /bin/bash /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/missing --run automake-1.9 --gnu
    /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/missing: line 52: automake-1.9: command not found
    WARNING: `automake-1.9' is missing on your system.  You should only need it if
	     you modified `Makefile.am', `acinclude.m4' or `configure.ac'.
	     You might want to install the `Automake' and `Perl' packages.
	     Grab them from any GNU archive site.
    cd . && /bin/bash /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/missing --run autoconf
    /bin/bash ./config.status --recheck
    running /bin/bash ./configure   --no-create --no-recursion
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking whether make sets $(MAKE)... (cached) yes
    checking for perl... /usr/bin/perl
    checking for rsync... /usr/bin/rsync
    checking for cp... /bin/cp
    checking for rm... /bin/rm
    checking for ssh... /usr/bin/ssh
    checking for lvcreate... no
    checking for lvremove... no
    checking for mount... /bin/mount
    checking for umount... /bin/umount
    checking for logger... /usr/bin/logger
    checking for du... /usr/bin/du
    configure: creating ./config.status

    Now type  "make test"    to run the regression test suite.
    Then type "make install" to install the program.

    After rsnapshot is installed, don't forget to copy
    /usr/local/etc/rsnapshot.conf.default to /usr/local/etc/rsnapshot.conf

     /bin/bash ./config.status
    config.status: creating Makefile
    config.status: WARNING:  'Makefile.in' seems to ignore the --datarootdir setting
    config.status: creating rsnapshot
    config.status: creating rsnapshot-diff
    config.status: creating rsnapshot.conf.default
    config.status: creating t/support/etc/configtest.conf
    config.status: creating t/support/etc/rsync.conf
    config.status: creating t/support/etc/gnu_cp.conf
    config.status: creating t/support/etc/relative_delete_bugfix.conf
    config.status: creating t/configtest.t
    config.status: creating t/rsync.t
    config.status: creating t/gnu_cp.t
    config.status: creating t/relative_delete_bugfix.t
    /usr/bin/pod2man -c '' -n 'rsnapshot' -r '' rsnapshot > rsnapshot.1
    /usr/bin/pod2man -c '' -n 'rsnapshot-diff' -r '' rsnapshot-diff > rsnapshot-diff.1

2. Use this config:

    $ diff -u rsnapshot.conf.default ../rsn.conf
    --- rsnapshot.conf.default      2015-07-26 18:07:17.043999255 +0300
    +++ ../rsn.conf 2015-07-26 18:07:32.992906393 +0300
    @@ -24,7 +24,7 @@

     # All snapshots will be stored under this root directory.
     #
    -snapshot_root  /var/cache/rsnapshot/
    +snapshot_root  /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/

     # If no_create_root is enabled, rsnapshot will not automatically create the
     # snapshot_root directory. This is particularly useful if you are backing
    @@ -111,7 +111,7 @@
     # 4     Extra Verbose   Show extra verbose information
     # 5     Debug mode      Everything
     #
    -verbose                2
    +verbose                3

     # Same as "verbose" above, but controls the amount of data sent to the
     # logfile, if one is being used. The default is 3.
    @@ -128,7 +128,7 @@
     # If you enable this, make sure the lockfile directory is not world
     # writable. Otherwise anyone can prevent the program from running.
     #
    -lockfile       /var/run/rsnapshot.pid
    +#lockfile      /var/run/rsnapshot.pid

     # By default, rsnapshot check lockfile, check if PID is running
     # and if not, consider lockfile as stale, then start
    @@ -227,9 +227,10 @@
     ###############################

     # LOCALHOST
    -backup /home/          localhost/
    -backup /etc/           localhost/
    -backup /usr/local/     localhost/
    +#backup        /home/          localhost/
    +#backup        /etc/           localhost/
    +#backup        /usr/local/     localhost/
    +backup /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/      localhost/      +rsync_long_args=--filter='. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter'
     #backup        /var/log/rsnapshot              localhost/
     #backup        /etc/passwd     localhost/
     #backup        /home/foo/My Documents/         localhost/

where rsync filter is

    $ cat ../etc.rsync-filter
    - .git/

3. And run..

    $ perl ./rsnapshot-program.pl -c ../rsn.conf hourly
    /bin/rm -rf /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/
    /bin/cp -al /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0 \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1
    /usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
	--filter='. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter' \
	--exclude=bkp /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/localhost/
    Unknown filter rule: `'. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter''
    rsync error: syntax or usage error (code 1) at exclude.c(904) [client=3.1.1]
    ----------------------------------------------------------------------------
    rsnapshot encountered an error! The program was invoked with these options:
    ./rsnapshot-program.pl -c ../rsn.conf hourly
    ----------------------------------------------------------------------------
    ERROR: /usr/bin/rsync returned 1 while processing /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/
    touch /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/

if i'll use script, which outputs its own arguments instead of rsync (in 'cmd_rsync'):

    $ cat ../lspp.sh
    #!/bin/sh

    for f; do
	echo "$f"
    done

i'll get

    $ perl ./rsnapshot-program.pl -c ../rsn.conf hourly
    /bin/rm -rf /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/
    /bin/cp -al /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0 \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1
    /home/sgf/Documents/rsnapshot/src/3rd/t/lspp.sh -a --delete --numeric-ids \
	--relative --delete-excluded --filter='. \
	/home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter' --exclude=bkp \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/localhost/
    -a
    --delete
    --numeric-ids
    --relative
    --delete-excluded
    --filter='. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter'
    --exclude=bkp
    /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot
    /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/localhost/
    touch /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/

(i.e. quotes are passed in argument, but they should be removed).

Without quotes

    backup /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/      localhost/      +rsync_long_args=--filter=. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter

this example does not work either:

    $ perl ./rsnapshot-program.pl -c ../rsn.conf hourly
    /bin/rm -rf /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.5/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.4/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.3/
    mv /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1/ \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.2/
    /bin/cp -al /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0 \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.1
    /usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
	--filter=. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter \
	--exclude=bkp /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot \
	/home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/localhost/
    unexpected end of filter rule: .
    rsync error: syntax or usage error (code 1) at exclude.c(1013) [client=3.1.1]
    ----------------------------------------------------------------------------
    rsnapshot encountered an error! The program was invoked with these options:
    ./rsnapshot-program.pl -c ../rsn.conf hourly
    ----------------------------------------------------------------------------
    ERROR: /usr/bin/rsync returned 1 while processing /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/
    touch /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/hourly.0/

Using this

    backup  /home/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/      localhost/      +rsync_long_args='--filter=. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter'

results in rsync treating --filter option as file:

    rsync: link_stat "/home/common/sgf/Documents/rsnapshot/src/3rd/t/rsnapshot/bkp/'--filter=. /home/sgf/Documents/rsnapshot/src/3rd/t/etc.rsync-filter'" failed: No such file or directory (2)

#793687#10
Date:
2015-09-03 20:41:22 UTC
From:
To:
I'm not 100% sure this is the same issue, but I found that my backup
scheme broke after upgrading rsnapshot. It concerned the --rsh option
and quotes concerning rsync_long_args.  No other changes were made.

I am using the backup schema as described at

http://dev.kprod.net/?q=linux-backup-rsnapshot-no-root

Although the rsync commands work when copied and pasted into the command
line, you'll see lots of errors like this:

rsync: Failed to exec /usr/bin/ssh -i /home/backupuser/.ssh/id_rsa: No
such file or directory (2)

rsync error: error in IPC code (code 14) at pipe.c(84) [Receiver=3.0.9]

I was able to resolve the issue by applying the patch from the rsnapshot
mailing list at

http://sourceforge.net/p/rsnapshot/mailman/rsnapshot-discuss/thread/CAFyR6OntWmuxJ1XsUhzHuP4XFE0xMaUz8vNXHgqDgNWK4DG8ZA@mail.gmail.com/

Perhaps this could be added to the Debian distro too.

I hope this helps!

Very warm regards, and thank you for Debian and Rsnapshot!

#793687#15
Date:
2015-09-06 10:55:32 UTC
From:
To:
Hello,

the current version in Jessie has got a regression then using ssh_args. This is a major
problem because most of our users are using extra ssh keys and this don't work at the
moment.

The patch that is working is backported from upstream to the version in Jessie:

https://github.com/hggh/rsnapshot-debian/compare/master...jessie.patch

The debdiff:

debdiff rsnapshot_1.3.1-4.dsc rsnapshot_1.3.1-4+deb8u1.dsc
(/tmp/build/rsnapshot_1.3.1-4+deb8u1.dsc) diff -Nru rsnapshot-1.3.1/debian/changelog
rsnapshot-1.3.1/debian/changelog --- rsnapshot-1.3.1/debian/changelog	2013-07-08
22:54:57.000000000 +0200 +++ rsnapshot-1.3.1/debian/changelog	2015-09-06
12:45:22.000000000 +0200 @@ -1,3 +1,12 @@
+rsnapshot (1.3.1-4+deb8u1) jessie; urgency=medium
+
+  * Fix regression on --rsh with args: Applied patch from Upstream to fix --rsh
+    command line arguments with quotes.
+    The --rsh=... argument to rsync was erroneously quoted when added to the
+    @rsync_long_args_stack with options set.
+
+ -- Jonas Genannt <genannt@debian.org>  Sun, 06 Sep 2015 12:33:41 +0200
+
 rsnapshot (1.3.1-4) unstable; urgency=low

   * debian/patches/01_rsnapshot_conf: Refresh patch to fix path of rsnapshot in
diff -Nru rsnapshot-1.3.1/debian/patches/14_fix_rsh_args.patch
rsnapshot-1.3.1/debian/patches/14_fix_rsh_args.patch ---
rsnapshot-1.3.1/debian/patches/14_fix_rsh_args.patch	1970-01-01 01:00:00.000000000
+0100 +++ rsnapshot-1.3.1/debian/patches/14_fix_rsh_args.patch	2015-09-06
12:45:22.000000000 +0200 @@ -0,0 +1,28 @@ +From f0b3b27d174257bf2a8ad29b8c36499bb7b2fb79
Mon Sep 17 00:00:00 2001 +From: Edwin Mons <git@home.mons.net>
+Date: Wed, 18 Sep 2013 22:39:11 +0200
+Subject: [PATCH] Fix --rsh commandline option
+Bug:
https://github.com/rsnapshot/rsnapshot/commit/30380587aeab201311af9428f7c47621ade691c8 +
+The --rsh=... argument to rsync was erroneously quoted when added to the
+@rsync_long_args_stack with options set.
+
+Test-Information:
+
+Unit tests pass.
+Tested and verified on Debian 7.0
+---
+ rsnapshot-program.pl | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/rsnapshot-program.pl
++++ b/rsnapshot-program.pl
+@@ -3452,7 +3452,7 @@
+
+ 		# if we have any args for SSH, add them
+ 		if ( defined($ssh_args) ) {
+-			push( @rsync_long_args_stack, "--rsh=\"$config_vars{'cmd_ssh'}
$ssh_args\"" ); ++			push( @rsync_long_args_stack,
"--rsh=$config_vars{'cmd_ssh'} $ssh_args" );
+
+ 		# no arguments is the default
+ 		} else {
diff -Nru rsnapshot-1.3.1/debian/patches/series rsnapshot-1.3.1/debian/patches/series
--- rsnapshot-1.3.1/debian/patches/series	2013-07-08 22:27:41.000000000 +0200
+++ rsnapshot-1.3.1/debian/patches/series	2015-09-06 12:45:22.000000000 +0200
@@ -8,3 +8,4 @@
 11_lvm_snapshots.diff
 12_include_conf_with_arguments.diff
 13_print_warn.diff
+14_fix_rsh_args.patch



Could you please provide a stable update?

Thanks,
	Jonas

#793687#22
Date:
2015-10-05 20:18:10 UTC
From:
To:
tags 793687 patch
thanks

It would be really great if a fixed package could be provided for Jessie.


Thanks & Greetings,

Paul

#793687#31
Date:
2021-06-04 00:23:50 UTC
From:
To:

#793687#38
Date:
2022-06-18 11:35:44 UTC
From:
To:
In #859099 this behaviour was pinpointed to the 10_space_destdir patch which was
 removed in version 1.4.0-1.

Closing as fixed.

Thanks

Mark