From 54048a339c3a13ae26b590333bd8906b3c9c6afc Mon Sep 17 00:00:00 2001 From: Alexander 'Leo' Bergolth Date: Thu, 28 Jul 2016 09:30:46 +0200 Subject: [PATCH] add new placeholder {borgversion} substitute placeholders in --remote-path add BORG_VERSION environment variable before executing ssh command --- borg/archiver.py | 11 ++++++++--- borg/helpers.py | 3 ++- borg/remote.py | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 74c1d1a41..ab9158aba 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -826,7 +826,8 @@ def do_break_lock(self, args, repository): EOF $ borg create --exclude-from exclude.txt backup /\n\n''') helptext['placeholders'] = textwrap.dedent(''' - Repository (or Archive) URLs and --prefix values support these placeholders: + Repository (or Archive) URLs, --prefix and --remote-path values support these + placeholders: {hostname} @@ -852,7 +853,11 @@ def do_break_lock(self, args, repository): The current process ID. - Examples:: + {borgversion} + + The version of borg. + + Examples:: borg create /path/to/repo::{hostname}-{user}-{utcnow} ... borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ... @@ -1064,7 +1069,7 @@ def build_parser(self, args=None, prog=None): checkpoints and treated in special ways. In the archive name, you may use the following format tags: - {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid} + {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid}, {borgversion} To speed up pulling backups over sshfs and similar network file systems which do not provide correct inode information the --ignore-inode flag can be used. This diff --git a/borg/helpers.py b/borg/helpers.py index 1a7bf8afc..bacb434ba 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -577,7 +577,8 @@ def replace_placeholders(text): 'hostname': socket.gethostname(), 'now': current_time.now(), 'utcnow': current_time.utcnow(), - 'user': uid2user(os.getuid(), os.getuid()) + 'user': uid2user(os.getuid(), os.getuid()), + 'borgversion': borg_version, } return format_line(text, data) diff --git a/borg/remote.py b/borg/remote.py index a8e64c127..10bde4bba 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -11,6 +11,7 @@ from . import __version__ from .helpers import Error, IntegrityError, sysinfo +from .helpers import replace_placeholders from .repository import Repository import msgpack @@ -155,6 +156,7 @@ def __init__(self, location, create=False, lock_wait=None, lock=True, args=None) # that the system's ssh binary picks up (non-matching) libraries from there env.pop('LD_LIBRARY_PATH', None) env.pop('BORG_PASSPHRASE', None) # security: do not give secrets to subprocess + env['BORG_VERSION'] = __version__ self.p = Popen(borg_cmd, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) self.stdin_fd = self.p.stdin.fileno() self.stdout_fd = self.p.stdout.fileno() @@ -221,6 +223,7 @@ def borg_cmd(self, args, testing): return [sys.executable, '-m', 'borg.archiver', 'serve'] + opts + self.extra_test_args else: # pragma: no cover remote_path = args.remote_path or os.environ.get('BORG_REMOTE_PATH', 'borg') + remote_path = replace_placeholders(remote_path) return [remote_path, 'serve'] + opts def ssh_cmd(self, location):