From 90348c1de9103ef867e5ca1cf3ec6a8b3c4bcf71 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 4 Aug 2018 15:01:48 +0200 Subject: [PATCH] add BORG_HOST_ID, fixes #3985 --- docs/usage_general.rst.inc | 7 +++++++ src/borg/platform/base.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/usage_general.rst.inc b/docs/usage_general.rst.inc index 39ac79ae0..ba2a214e2 100644 --- a/docs/usage_general.rst.inc +++ b/docs/usage_general.rst.inc @@ -185,6 +185,13 @@ General: Borg assumes that it can derive a unique hostname / identity (see ``borg debug info``). If this is not the case or you do not want Borg to automatically remove stale locks, set this to *no*. + BORG_HOST_ID + Borg usually computes a host id from the FQDN plus the results of ``uuid.getnode()`` (which usually returns + a unique id based on the MAC address of the network interface. Except if that MAC happens to be all-zero - in + that case it returns a random value, which is not what we want (because it kills automatic stale lock removal). + So, if you have a all-zero MAC address or other reasons to better externally control the host id, just set this + environment variable to a unique value. If all your FQDNs are unique, you can just use the FQDN. If not, + use fqdn@uniqueid. BORG_LOGGING_CONF When set, use the given filename as INI_-style logging configuration. BORG_RSH diff --git a/src/borg/platform/base.py b/src/borg/platform/base.py index f9fa55c49..c4e11f270 100644 --- a/src/borg/platform/base.py +++ b/src/borg/platform/base.py @@ -249,7 +249,13 @@ def getfqdn(name=''): # XXX this sometimes requires live internet access for issuing a DNS query in the background. hostname = socket.gethostname() fqdn = getfqdn(hostname) -hostid = '%s@%s' % (fqdn, uuid.getnode()) + +# uuid.getnode() is problematic in some environments (e.g. OpenVZ, see #3968) where the virtual MAC address +# is all-zero. uuid.getnode falls back to returning a random value in that case, which is not what we want. +# thus, we offer BORG_HOST_ID where a user can set an own, unique id for each of his hosts. +hostid = os.environ.get('BORG_HOST_ID') +if not hostid: + hostid = '%s@%s' % (fqdn, uuid.getnode()) def get_process_id():