ソースを参照

add BORG_HOST_ID, fixes #3985

Thomas Waldmann 6 年 前
コミット
90348c1de9
2 ファイル変更14 行追加1 行削除
  1. 7 0
      docs/usage_general.rst.inc
  2. 7 1
      src/borg/platform/base.py

+ 7 - 0
docs/usage_general.rst.inc

@@ -185,6 +185,13 @@ General:
         Borg assumes that it can derive a unique hostname / identity (see ``borg debug info``).
         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,
         If this is not the case or you do not want Borg to automatically remove stale locks,
         set this to *no*.
         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
     BORG_LOGGING_CONF
         When set, use the given filename as INI_-style logging configuration.
         When set, use the given filename as INI_-style logging configuration.
     BORG_RSH
     BORG_RSH

+ 7 - 1
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.
 # XXX this sometimes requires live internet access for issuing a DNS query in the background.
 hostname = socket.gethostname()
 hostname = socket.gethostname()
 fqdn = getfqdn(hostname)
 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():
 def get_process_id():