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.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -425,35 +425,44 @@ def do_migrate_to_repokey(self, args, repository):
 
     def do_benchmark_crud(self, args):
         """Benchmark Create, Read, Update, Delete for archives."""
-        def measurement_run(repo, path):
+        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(args, path):
+            repo = args.location.canonical_path()
             archive = repo + '::borg-benchmark-crud'
             compression = '--compression=none'
             # measure create perf (without files cache to always have it chunking)
             t_start = time.monotonic()
-            rc = self.do_create(self.parse_args(['create', compression, '--files-cache=disabled', archive + '1', path]))
+            rc = self.do_create(parse_args(args, ['create', compression, '--files-cache=disabled', archive + '1', path]))
             t_end = time.monotonic()
             dt_create = t_end - t_start
             assert rc == 0
             # now build files cache
-            rc1 = self.do_create(self.parse_args(['create', compression, archive + '2', path]))
-            rc2 = self.do_delete(self.parse_args(['delete', archive + '2']))
+            rc1 = self.do_create(parse_args(args, ['create', compression, archive + '2', path]))
+            rc2 = self.do_delete(parse_args(args, ['delete', archive + '2']))
             assert rc1 == rc2 == 0
             # measure a no-change update (archive1 is still present)
             t_start = time.monotonic()
-            rc1 = self.do_create(self.parse_args(['create', compression, archive + '3', path]))
+            rc1 = self.do_create(parse_args(args, ['create', compression, archive + '3', path]))
             t_end = time.monotonic()
             dt_update = t_end - t_start
-            rc2 = self.do_delete(self.parse_args(['delete', archive + '3']))
+            rc2 = self.do_delete(parse_args(args, ['delete', archive + '3']))
             assert rc1 == rc2 == 0
             # measure extraction (dry-run: without writing result to disk)
             t_start = time.monotonic()
-            rc = self.do_extract(self.parse_args(['extract', '--dry-run', archive + '1']))
+            rc = self.do_extract(parse_args(args, ['extract', '--dry-run', archive + '1']))
             t_end = time.monotonic()
             dt_extract = t_end - t_start
             assert rc == 0
             # measure archive deletion (of LAST present archive with the data)
             t_start = time.monotonic()
-            rc = self.do_delete(self.parse_args(['delete', archive + '1']))
+            rc = self.do_delete(parse_args(args, ['delete', archive + '1']))
             t_end = time.monotonic()
             dt_delete = t_end - t_start
             assert rc == 0
@@ -491,7 +500,7 @@ def test_files(path, count, size, random):
 
         for msg, count, size, random in tests:
             with test_files(args.path, count, size, random) as path:
-                dt_create, dt_update, dt_extract, dt_delete = measurement_run(args.location.canonical_path(), path)
+                dt_create, dt_update, dt_extract, dt_delete = measurement_run(args, path)
             total_size_MB = count * size / 1e06
             file_size_formatted = format_file_size(size)
             content = 'random' if random else 'all-zero'


Test patch: