Repository: borgbackup/borg

Issue:
debug-info command
writing up the #1107 bug report, i realized i went through a number of steps that seem intuitive to me, but that are not necessarily obvious to users. furthermore, I had to type down a bunch of commands by hand, which is annoying.

it would be nice if there was a borg-maintained single command that would wrap together a list of properties that are important to submit as part of a bug report. to quote #1107, what I used there is:

```
root@marcos:~# lsb_release -d
Description:    Debian GNU/Linux 8.4 (jessie)
root@marcos:~# uname -a
Linux marcos 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-1 (2016-03-06) x86_64 GNU/Linux
root@marcos:~# borg --version
borg 1.0.2
root@marcos:~# borg  list /media/sdc2/borg | wc -l 
500
root@marcos:~# time borg info /media/sdc2/borg/::marcos-2016-05-30
Name: marcos-2016-05-30
Fingerprint: dd79e1d17c0d1a3f57f3f7663dae37b0193104a321d37da07f2f5f474f1d2924
Hostname: marcos
Username: root
Time (start): Mon, 2016-05-30 07:38:54
Time (end):   Mon, 2016-05-30 07:52:55
Command line: /usr/bin/borg create --one-file-system --verbose --stats /media/sdc2/borg::marcos-2016-05-30 / /boot /usr /var /home --exclude-caches --exclude /home/*/.cache --exclude */.Trash-* --exclude */[Cc]ache/* --exclude */.bitcoin/blocks/* --exclude *.vmdk --exclude /tmp/* --exclude */build-area/* --exclude /proc/* --exclude /dev/* --exclude /sys/* --exclude /var/cache/* --exclude /var/tmp/* --exclude /var/log/*
Number of files: 1698760

                       Original size      Compressed size    Deduplicated size
This archive:              212.73 GB            187.30 GB            590.28 MB
All archives:              142.37 TB            125.27 TB            671.69 GB

                       Unique chunks         Total chunks
Chunk index:                14719975           2897409051

real    0m57.973s
user    0m20.528s
sys     0m9.272s
```

or, as a list:
- `lsb_release -b`: operating system name, version and codename (`Debian GNU/Linux 8.4 (jessie)`)
- `uname -a`: kernel version, architecture and build dates (`Linux marcos 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-1 (2016-03-06) x86_64 GNU/Linux`)
- `borg --version`: self-explanatory
- `borg  list /media/sdc2/borg | wc -l`: the number of archives in the repository
- `time borg info /media/sdc2/borg/::marcos-2016-05-30`: the size of the last archive, with some timing information

I realize that I forgot to mention the python version number, which should include the compiler version. I wonder if we don't want to extract certain parts of the environment as well.

it would also be great if `borg info` would operate without an archive name, to give information about a whole repository without having to guess the archive name.



Discussion:
note: some of these infos are already output if an exception happens.

so, the first step would be to maybe add more useful stuff there and then reuse the same code for debug-info command (so one can get it even without an exception happening).


Resolving patch:
diff --git a/borg/archiver.py b/borg/archiver.py
--- a/borg/archiver.py
+++ b/borg/archiver.py
@@ -666,6 +666,11 @@ def do_upgrade(self, args):
             print("warning: %s" % e)
         return self.exit_code
 
+    def do_debug_info(self, args):
+        """display system information for debugging / bug reports"""
+        print(sysinfo())
+        return EXIT_SUCCESS
+
     @with_repository()
     def do_debug_dump_archive_items(self, args, repository, manifest, key):
         """dump (decrypted, decompressed) archive items metadata (not: data)"""
@@ -1487,6 +1492,18 @@ def build_parser(self, args=None, prog=None):
         subparser.add_argument('topic', metavar='TOPIC', type=str, nargs='?',
                                help='additional help on TOPIC')
 
+        debug_info_epilog = textwrap.dedent("""
+        This command displays some system information that might be useful for bug
+        reports and debugging problems. If a traceback happens, this information is
+        already appended at the end of the traceback.
+        """)
+        subparser = subparsers.add_parser('debug-info', parents=[common_parser],
+                                          description=self.do_debug_info.__doc__,
+                                          epilog=debug_info_epilog,
+                                          formatter_class=argparse.RawDescriptionHelpFormatter,
+                                          help='show system infos for debugging / bug reports (debug)')
+        subparser.set_defaults(func=self.do_debug_info)
+
         debug_dump_archive_items_epilog = textwrap.dedent("""
         This command dumps raw (but decrypted and decompressed) archive items (only metadata) to files.
         """)


Test patch: