Repository: borgbackup/borg

Issue:
`borg benchmark crud` does not respect `--remote-path`
<!--
Thank you for reporting an issue.

*IMPORTANT* -  *before* creating a new issue please look around:
 - Borgbackup documentation: http://borgbackup.readthedocs.io/en/stable/index.html
 - FAQ: https://borgbackup.readthedocs.io/en/stable/faq.html
 and
 - open issues in GitHub tracker: https://github.com/borgbackup/borg/issues
  
If you cannot find a similar problem, then create a new issue.

Please fill in as much of the template as possible.
-->

## Have you checked borgbackup docs, FAQ, and open GitHub issues?

Yes

## Is this a BUG / ISSUE report or a QUESTION?

Bug

## System information. For client/server mode post info for both machines.

#### Your borg version (borg -V).

Local = `1.2.7`
Remote `0.2.9` / `1.2.7`

#### Full borg commandline that lead to the problem (leave away excludes and passwords)


`borg --remote-path borg1 benchmark crud user@user.rsync.net:test`

## Describe the problem you're observing.

I am trying run a benchmark on an rsync.net server.  rsync.net runs an outdated version of borg by default (`0.2.9`).  In order to use `v1.x` the client is required to send `--remote-path borg1` with each command.

If the argument is not set then a version mismatch warning is displayed.

When `borg --remote-path borg1 benchmark crud user@user.rsync.net:test` the version mismatch is displayed, despite setting the argument.  This suggests that this command is not respecting the `--remote-path` argument and running the default `borg` path on the server, rather than the requested `borg1`.

In addition, I am getting a `borg.repository.DoesNotExist: /test` error, but this may be to do with the mismatched versions, so I figured I would work that out first then move on to that.

#### Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.

```
borg --remote-path borg1 user@user.rsync.net:test
borg --remote-path borg1 benchmark crud user@user.rsync.net:test`
```

#### Include any warning/errors/backtraces from the system logs
```

$ borg --remote-path=borg1 init -e none ***@***.rsync.net:test
$ borg --remote-path=borg1 benchmark crud "***@***.rsync.net:./test" ./bm
Remote: Borg 0.29.0: exception in RPC call:
Remote: Traceback (most recent call last):
Remote:   File "/usr/home/kibab/borgbackup-0.29.0/borg/remote.py", line 96, in serve
Remote: TypeError: open() takes from 2 to 5 positional arguments but 7 were given
Remote: Command 'uname -p 2> /dev/null' is not in the allowed list.
Remote: Platform: FreeBSD ch-s014.rsync.net 13.1-RELEASE-p3 FreeBSD 13.1-RELEASE-p3 rsync_13_1 amd64
Remote: Python: CPython 3.4.3
Remote: 
Please note:
If you see a TypeError complaining about the number of positional arguments
given to open(), you can ignore it if it comes from a borg version < 1.0.7.
This TypeError is a cosmetic side effect of the compatibility code borg
clients >= 1.0.7 have to support older borg servers.
This problem will go away as soon as the server has been upgraded to 1.0.7+.
Remote: Borg 0.29.0: exception in RPC call:
Remote: Traceback (most recent call last):
Remote:   File "/usr/home/kibab/borgbackup-0.29.0/borg/remote.py", line 96, in serve
Remote:   File "/usr/home/kibab/borgbackup-0.29.0/borg/remote.py", line 121, in open
Remote:   File "/usr/home/kibab/borgbackup-0.29.0/borg/repository.py", line 63, in __init__
Remote:   File "/usr/home/kibab/borgbackup-0.29.0/borg/repository.py", line 139, in open
Remote: borg.repository.DoesNotExist: /test
Remote: Platform: FreeBSD ch-s014.rsync.net 13.1-RELEASE-p3 FreeBSD 13.1-RELEASE-p3 rsync_13_1 amd64
Remote: Python: CPython 3.4.3
Remote: 
Repository ssh://***@***.rsync.net/./test does not exist.

```


Discussion:

Resolving patch:
diff --git a/src/borg/archiver/benchmark_cmd.py b/src/borg/archiver/benchmark_cmd.py
--- a/src/borg/archiver/benchmark_cmd.py
+++ b/src/borg/archiver/benchmark_cmd.py
@@ -18,13 +18,22 @@ class BenchmarkMixIn:
     def do_benchmark_crud(self, args):
         """Benchmark Create, Read, Update, Delete for archives."""
 
+        def parse_args(args, cmd):
+            # we need to inherit some essential options from the "borg benchmark crud" invocation
+            if args.rsh is not None:
+                cmd[1:1] = ["--rsh", args.rsh]
+            if args.remote_path is not None:
+                cmd[1:1] = ["--remote-path", args.remote_path]
+            return self.parse_args(cmd)
+
         def measurement_run(repo, path):
             compression = "--compression=none"
             # measure create perf (without files cache to always have it chunking)
             t_start = time.monotonic()
             rc = get_reset_ec(
                 self.do_create(
-                    self.parse_args(
+                    parse_args(
+                        args,
                         [
                             f"--repo={repo}",
                             "create",
@@ -32,7 +41,7 @@ def measurement_run(repo, path):
                             "--files-cache=disabled",
                             "borg-benchmark-crud1",
                             path,
-                        ]
+                        ],
                     )
                 )
             )
@@ -41,27 +50,31 @@ def measurement_run(repo, path):
             assert rc == 0
             # now build files cache
             rc1 = get_reset_ec(
-                self.do_create(self.parse_args([f"--repo={repo}", "create", compression, "borg-benchmark-crud2", path]))
+                self.do_create(
+                    parse_args(args, [f"--repo={repo}", "create", compression, "borg-benchmark-crud2", path])
+                )
             )
             rc2 = get_reset_ec(
-                self.do_delete(self.parse_args([f"--repo={repo}", "delete", "-a", "borg-benchmark-crud2"]))
+                self.do_delete(parse_args(args, [f"--repo={repo}", "delete", "-a", "borg-benchmark-crud2"]))
             )
             assert rc1 == rc2 == 0
             # measure a no-change update (archive1 is still present)
             t_start = time.monotonic()
             rc1 = get_reset_ec(
-                self.do_create(self.parse_args([f"--repo={repo}", "create", compression, "borg-benchmark-crud3", path]))
+                self.do_create(
+                    parse_args(args, [f"--repo={repo}", "create", compression, "borg-benchmark-crud3", path])
+                )
             )
             t_end = time.monotonic()
             dt_update = t_end - t_start
             rc2 = get_reset_ec(
-                self.do_delete(self.parse_args([f"--repo={repo}", "delete", "-a", "borg-benchmark-crud3"]))
+                self.do_delete(parse_args(args, [f"--repo={repo}", "delete", "-a", "borg-benchmark-crud3"]))
             )
             assert rc1 == rc2 == 0
             # measure extraction (dry-run: without writing result to disk)
             t_start = time.monotonic()
             rc = get_reset_ec(
-                self.do_extract(self.parse_args([f"--repo={repo}", "extract", "borg-benchmark-crud1", "--dry-run"]))
+                self.do_extract(parse_args(args, [f"--repo={repo}", "extract", "borg-benchmark-crud1", "--dry-run"]))
             )
             t_end = time.monotonic()
             dt_extract = t_end - t_start
@@ -69,7 +82,7 @@ def measurement_run(repo, path):
             # measure archive deletion (of LAST present archive with the data)
             t_start = time.monotonic()
             rc = get_reset_ec(
-                self.do_delete(self.parse_args([f"--repo={repo}", "delete", "-a", "borg-benchmark-crud1"]))
+                self.do_delete(parse_args(args, [f"--repo={repo}", "delete", "-a", "borg-benchmark-crud1"]))
             )
             t_end = time.monotonic()
             dt_delete = t_end - t_start


Test patch: