Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 75d59e9

Browse files
committed
Remove --reverse parameter
The --reverse parameter, used for transforming a "backup" operation into a "restore" by simply adding a parameter was a good idea but makes the code unnecessarily complex. Also, it is hard to test sufficiently as the number of parameter combinations that would require testing explodes with more parameters being added. This change removes the --reverse parameter and the associated code in an attempt to simplify the internals slightly.
1 parent 548dd37 commit 75d59e9

File tree

3 files changed

+12
-76
lines changed

3 files changed

+12
-76
lines changed

btrfs-backup/README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ the following command can be used:
7373

7474
``$ btrfs-backup restore --subvolume=subvolume/ backup/ snapshots/``
7575

76-
Alternatively, you can use the --reverse option to keep the order of the
77-
source and destination repository that was used during backup (as
78-
opposed to restoration). This option exists for convenience only, so
79-
that not the entire command line has to be amended but only one word
80-
replaced and an option appended to convert a backup operation into a
81-
restore operation.
82-
83-
```
84-
$ btrfs-backup restore --reverse
85-
--subvolume=subvolume/ snapshots/ backup/
86-
```
87-
8876
The above step for restoration assumes that the subvolume you initially
8977
backed up got deleted. However, under certain circumstances it might be
9078
the case that you only want to restore the snapshots (the read-only
@@ -171,8 +159,7 @@ stream might not result in much savings of bandwidth since it is
171159
reasonable to believe that the btrfs program already creates a
172160
sufficiently compressed stream of data.
173161
Note furthermore that since filters are sensitive to ordering, they have
174-
to be reordered for the restore case unless the --reverse option
175-
(explained above) is used.
162+
to be reordered for the restore case.
176163
Lastly, note that filtering can be combined with remote command
177164
execution as one would naively expect.
178165

btrfs-backup/src/deso/btrfs/main.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,6 @@ def checkSnapshotExtension(string):
129129
return "%s%s" % (extsep, string)
130130

131131

132-
class ReverseAction(Action):
133-
"""Action to reverse some source/destination arguments."""
134-
def __init__(self, option_strings, dest, const=None, default=None,
135-
required=False, help=None, metavar=None):
136-
"""Create a new ReverseAction object."""
137-
super().__init__(option_strings=option_strings, dest=dest, nargs=0,
138-
const=const, default=default, required=required,
139-
help=help)
140-
141-
142-
def __call__(self, parser, namespace, values, option_string=None):
143-
"""Helper function to reverse arguments during parsing."""
144-
# In case the reverse option was given we swap the repositories and
145-
# the filters.
146-
with alias(namespace) as ns:
147-
ns.src, ns.dst = ns.dst, ns.src
148-
ns.send_filters, ns.recv_filters = ns.recv_filters, ns.send_filters
149-
150-
151132
class CheckSnapshotExtensionAction(Action):
152133
"""Action to check correct usage of the --snapshot-ext parameter."""
153134
def __init__(self, option_strings, dest, nargs=None, const=None,
@@ -241,11 +222,6 @@ def addOptionalArgs(parser, backup):
241222
"to include the full path to the binary or script, e.g., "
242223
"\"/usr/bin/ssh server\".",
243224
)
244-
parser.add_argument(
245-
"--reverse", action=ReverseAction, dest="reverse",
246-
help="Reverse (i.e., swap) the source and destination repositories "
247-
"as well as the send and receive filters.",
248-
)
249225
parser.add_argument(
250226
"--send-filter", action="append", default=None, dest="send_filters",
251227
metavar="command", nargs=1,
@@ -427,14 +403,12 @@ def prepare(filters):
427403
# not be a valid command.
428404
remote_cmd = remote_cmd.split()
429405

430-
# Note that intuitively only the send filters can contain a None
431-
# element in case the --join option is supplied. However, in case we
432-
# have a --reverse option as well the filters could get swapped (which
433-
# always happens after the insertion of the empty element).
406+
# The send filters might contain a None element in case the --join
407+
# option is supplied. Handle this case correctly.
434408
if send_filters:
435409
send_filters = prepare(send_filters)
436410
if recv_filters:
437-
recv_filters = prepare(recv_filters)
411+
recv_filters = split(recv_filters)
438412

439413
ns.recv_filters = recv_filters
440414
ns.send_filters = send_filters
@@ -448,7 +422,6 @@ def prepare(filters):
448422
del ns.src
449423
del ns.dst
450424
del ns.command
451-
del ns.reverse
452425

453426
return command, subvolumes, src_repo, dst_repo
454427

@@ -477,16 +450,7 @@ def main(argv):
477450
# that end, we move it to the end of the options because the
478451
# ArgumentParser evaluates arguments in the order in which they are
479452
# provided in the argument vector.
480-
# In order to have less branching in various cases, we want to
481-
# evaluate the --reverse option on the fly. This option has a special
482-
# action that reverses the source and destination repositories as well
483-
# as the send and receive filters. However, in order for it to work
484-
# correctly, it needs to be evaluated just before the --snapshot-ext
485-
# option (because the latter requires the reordered arguments) but
486-
# after all other options. Hence, we move it to the end right before
487-
# we do the same with the --snapshot-ext option.
488453
args = argv[1:].copy()
489-
args = reorderArg(args, "--reverse", has_arg=False)
490454
args = reorderArg(args, "--snapshot-ext", has_arg=True)
491455
namespace = parser.parse_args(args)
492456

btrfs-backup/src/deso/btrfs/test/testMain.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# testMain.py
22

33
#/***************************************************************************
4-
# * Copyright (C) 2015 Daniel Mueller (deso@posteo.net) *
4+
# * Copyright (C) 2015-2016 Daniel Mueller (deso@posteo.net) *
55
# * *
66
# * This program is free software: you can redistribute it and/or modify *
77
# * it under the terms of the GNU General Public License as published by *
@@ -438,20 +438,7 @@ def performTest(self, backup, restore, src, dst):
438438
self.assertContains(m.path(user, "data", "movie.mp4"), "abcdefgh")
439439
self.assertContains(m.path(root, ".ssh", "key.pub"), "1234567890")
440440

441-
# Case 3) Once again delete all snapshots but this time
442-
# restore them in conjunction with the --reverse
443-
# option.
444-
self.wipeSubvolumes(self._snapshots)
445-
446-
# This time we use the '--reverse' option.
447-
restore("--reverse", "--snapshots-only", src, dst, reverse=True)
448-
449-
user, root = glob(m.path("snapshots", "*"))
450-
451-
self.assertContains(m.path(user, "data", "movie.mp4"), "abcdefgh")
452-
self.assertContains(m.path(root, ".ssh", "key.pub"), "1234567890")
453-
454-
# Case 4) Also delete the original subvolumes we snapshotted
441+
# Case 3) Also delete the original subvolumes we snapshotted
455442
# and verify that they can be restored as well.
456443
self.wipeSubvolumes(m.path("home"))
457444
self.wipeSubvolumes(m.path(), pattern="root")
@@ -514,9 +501,8 @@ def backup(src, dst, *options):
514501
]
515502
self.backup(src, dst, *options)
516503

517-
def restore(src, dst, *options, reverse=False):
504+
def restore(src, dst, *options):
518505
"""Invoke the program to restore snapshots/subvolumes from an encrypted source."""
519-
filt = "recv" if reverse else "send"
520506
gpg_options = "--decrypt --no-default-keyring "\
521507
"--keyring={pubkey} --secret-keyring={privkey} "\
522508
"--trust-model=always --batch {{file}}"
@@ -525,10 +511,10 @@ def restore(src, dst, *options, reverse=False):
525511
options = list(options)
526512
options += [
527513
"--snapshot-ext=gpg",
528-
"--%s-filter=%s %s" % (filt, GPG, gpg_options),
514+
"--send-filter=%s %s" % (GPG, gpg_options),
529515
"--join",
530516
]
531-
self.restore(src, dst, *options, reverse=reverse)
517+
self.restore(src, dst, *options)
532518
try:
533519
GPG = findCommand("gpg")
534520
except FileNotFoundError:
@@ -591,17 +577,16 @@ def backup(*options):
591577
]
592578
self.backup(*options)
593579

594-
def restore(src, dst, *options, reverse=False):
580+
def restore(src, dst, *options):
595581
"""Invoke the program to restore snapshots/subvolumes from a remote host."""
596-
filt = "recv" if reverse else "send"
597582
options = list(options)
598583
options += [
599584
"--remote-cmd=/usr/bin/ssh %s" % host,
600585
"--snapshot-ext=bin",
601-
"--%s-filter=/bin/dd if={file}" % filt,
586+
"--send-filter=/bin/dd if={file}",
602587
"--no-read-stderr",
603588
]
604-
self.restore(src, dst, *options, reverse=reverse)
589+
self.restore(src, dst, *options)
605590

606591
try:
607592
SSH = findCommand("ssh")

0 commit comments

Comments
 (0)