소스 검색

Merge pull request #3429 from pngwjpgh/feat/reverse-fqdn

Add placeholder for fqdn in reverse notation
TW 7 년 전
부모
커밋
59ac75cf17
4개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 0
      docs/man/borg-placeholders.1
  2. 3 0
      docs/usage/help.rst.inc
  3. 3 0
      src/borg/archiver.py
  4. 3 1
      src/borg/helpers/parseformat.py

+ 3 - 0
docs/man/borg-placeholders.1

@@ -42,6 +42,9 @@ The (short) hostname of the machine.
 .B {fqdn}
 .B {fqdn}
 The full name of the machine.
 The full name of the machine.
 .TP
 .TP
+.B {reverse-fqdn}
+The full name of the machine in reverse domain name notation.
+.TP
 .B {now}
 .B {now}
 The current local date and time, by default in ISO\-8601 format.
 The current local date and time, by default in ISO\-8601 format.
 You can also supply your own \fI\%format string\fP, e.g. {now:%Y\-%m\-%d_%H:%M:%S}
 You can also supply your own \fI\%format string\fP, e.g. {now:%Y\-%m\-%d_%H:%M:%S}

+ 3 - 0
docs/usage/help.rst.inc

@@ -169,6 +169,9 @@ placeholders:
 {fqdn}
 {fqdn}
     The full name of the machine.
     The full name of the machine.
 
 
+{reverse-fqdn}
+    The full name of the machine in reverse domain name notation.
+
 {now}
 {now}
     The current local date and time, by default in ISO-8601 format.
     The current local date and time, by default in ISO-8601 format.
     You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
     You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}

+ 3 - 0
src/borg/archiver.py

@@ -1901,6 +1901,9 @@ class Archiver:
         {fqdn}
         {fqdn}
             The full name of the machine.
             The full name of the machine.
 
 
+        {reverse-fqdn}
+            The full name of the machine in reverse domain name notation.
+
         {now}
         {now}
             The current local date and time, by default in ISO-8601 format.
             The current local date and time, by default in ISO-8601 format.
             You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
             You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}

+ 3 - 1
src/borg/helpers/parseformat.py

@@ -180,9 +180,11 @@ def format_line(format, data):
 def replace_placeholders(text):
 def replace_placeholders(text):
     """Replace placeholders in text with their values."""
     """Replace placeholders in text with their values."""
     current_time = datetime.now()
     current_time = datetime.now()
+    fqdn = socket.getfqdn()
     data = {
     data = {
         'pid': os.getpid(),
         'pid': os.getpid(),
-        'fqdn': socket.getfqdn(),
+        'fqdn': fqdn,
+        'reverse-fqdn': '.'.join(reversed(fqdn.split('.'))),
         'hostname': socket.gethostname(),
         'hostname': socket.gethostname(),
         'now': DatetimeWrapper(current_time.now()),
         'now': DatetimeWrapper(current_time.now()),
         'utcnow': DatetimeWrapper(current_time.utcnow()),
         'utcnow': DatetimeWrapper(current_time.utcnow()),