Skip to content

Commit d771961

Browse files
dschnellertimvaillancourt
authored andcommitted
Add --archive.tar.binary parameter (#286)
* Add --archive.tar.binary parameter Allows specifying a custom location of the "tar" command to use. Also, the flags sent to "tar" are sent individually (`tar -cf` becomes `tar -c -f`). This allows easily customizing how the archiving is performed without having to add lots of new options. For example, you could encrypt backup data via a simple shell script and specify it for --archive.tar.binary: ``` #!/bin/bash gpg_pubkey_id=XXXXXXX new_args="" while [ "${#}" -gt 0 ]; do case "$1" in -f) shift; original_output_file="${1}" shift new_args="${new_args} --to-stdout" ;; *) new_args="${new_args} ${1}" shift ;; esac done tar ${new_args} | gpg --always-trust --encrypt --recipient ${gpg_pubkey_id} -z 0 --output ${original_output_file} ``` This has several advantages: * Backups are never written to disk unencrypted * Encryption can be done in one go, instead of causing the potentially heavy additional I/O a separate encryption step would incur. * It's transparent for the upload stages, so you can still benefit from the integrated S3 (or other) uploads. * Related: Fix flake8: Make regex a raw string
1 parent 0f529ca commit d771961

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

mongodb_consistent_backup/Archive/Tar/Tar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Tar(Task):
2626
def __init__(self, manager, config, timer, base_dir, backup_dir, **kwargs):
2727
super(Tar, self).__init__(self.__class__.__name__, manager, config, timer, base_dir, backup_dir, **kwargs)
2828
self.compression_method = self.config.archive.tar.compression
29-
self.binary = "tar"
29+
self.binary = self.config.archive.tar.binary
3030

3131
self._pool = None
3232
self._pooled = []

mongodb_consistent_backup/Archive/Tar/TarThread.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ def run(self):
3232
backup_base_name = os.path.basename(self.backup_dir)
3333

3434
log_msg = "Archiving directory: %s" % self.backup_dir
35-
cmd_flags = ["-C", backup_base_dir, "-cf", self.output_file, "--remove-files", backup_base_name]
35+
cmd_flags = ["-C", backup_base_dir, "-c", "-f", self.output_file, "--remove-files"]
3636

3737
if self.do_gzip():
38-
log_msg = "Archiving and compressing directory: %s" % self.backup_dir
39-
cmd_flags = ["-C", backup_base_dir, "-czf", self.output_file, "--remove-files", backup_base_name]
38+
log_msg = "Archiving and compressing directory: %s" % self.backup_dir
39+
cmd_flags.append("-z")
4040

41+
cmd_flags.append(backup_base_name)
4142
logging.info(log_msg)
4243
self.running = True
4344
self._command = LocalCommand(self.binary, cmd_flags, self.verbose)

mongodb_consistent_backup/Archive/Tar/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
def config(parser):
5+
parser.add_argument("--archive.tar.binary", dest="archive.tar.binary", default='tar', type=str,
6+
help="Path to tar binary (default: tar)")
57
parser.add_argument("--archive.tar.compression", dest="archive.tar.compression",
68
help="Tar archiver compression method (default: gzip)", default='gzip', choices=['gzip', 'none'])
79
parser.add_argument("--archive.tar.threads", dest="archive.tar.threads",

0 commit comments

Comments
 (0)