Blame SOURCES/sos-bz1494420-postgresql-scl-path.patch

7b9b39
From 0b93d1f69ccfcc76e1896ea0e5ff7854be69be13 Mon Sep 17 00:00:00 2001
7b9b39
From: Pavel Moravec <pmoravec@redhat.com>
7b9b39
Date: Sat, 25 Nov 2017 12:47:35 +0100
7b9b39
Subject: [PATCH] [plugins] set proper PATH for SCL commands
7b9b39
7b9b39
As SCL packages are deployed under /opt/${provider}/${scl}/,
7b9b39
calling a SCL command needs that prefix in any path in PATH.
7b9b39
7b9b39
Consequently, distro-specific SCL default path prefix of the provider must be
7b9b39
defined in sos policies.
7b9b39
7b9b39
Relevant to: #1154
7b9b39
7b9b39
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
7b9b39
---
7b9b39
 sos/plugins/__init__.py  | 37 ++++++++++++++++++++++++++++++-------
7b9b39
 sos/policies/__init__.py |  4 ++++
7b9b39
 sos/policies/redhat.py   |  1 +
7b9b39
 3 files changed, 35 insertions(+), 7 deletions(-)
7b9b39
7b9b39
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
7b9b39
index aa69b19d..2a8bc516 100644
7b9b39
--- a/sos/plugins/__init__.py
7b9b39
+++ b/sos/plugins/__init__.py
7b9b39
@@ -1066,25 +1066,48 @@ class SCLPlugin(RedHatPlugin):
7b9b39
         output = sos_get_command_output("scl -l")["output"]
7b9b39
         return [scl.strip() for scl in output.splitlines()]
7b9b39
 
7b9b39
+    def convert_cmd_scl(self, scl, cmd):
7b9b39
+        """wrapping command in "scl enable" call and adds proper PATH
7b9b39
+        """
7b9b39
+        # load default SCL prefix to PATH
7b9b39
+        prefix = self.policy().get_default_scl_prefix()
7b9b39
+        # read prefix from /etc/scl/prefixes/${scl} and strip trailing '\n'
7b9b39
+        try:
7b9b39
+            prefix = open('/etc/scl/prefixes/%s' % scl, 'r').read()\
7b9b39
+                     .rstrip('\n')
7b9b39
+        except Exception as e:
7b9b39
+            self._log_error("Failed to find prefix for SCL %s, using %s"
7b9b39
+                            % (scl, prefix))
7b9b39
+
7b9b39
+        # expand PATH by equivalent prefixes under the SCL tree
7b9b39
+        path = os.environ["PATH"]
7b9b39
+        for p in path.split(':'):
7b9b39
+            path = '%s/%s%s:%s' % (prefix, scl, p, path)
7b9b39
+
7b9b39
+        scl_cmd = "scl enable %s \"PATH=%s %s\"" % (scl, path, cmd)
7b9b39
+        return scl_cmd
7b9b39
+
7b9b39
     def add_cmd_output_scl(self, scl, cmds, **kwargs):
7b9b39
         """Same as add_cmd_output, except that it wraps command in
7b9b39
-        "scl enable" call.
7b9b39
+        "scl enable" call and sets proper PATH.
7b9b39
         """
7b9b39
         if isinstance(cmds, six.string_types):
7b9b39
             cmds = [cmds]
7b9b39
         scl_cmds = []
7b9b39
-        scl_cmd_tpl = "scl enable %s \"%s\""
7b9b39
         for cmd in cmds:
7b9b39
-            scl_cmds.append(scl_cmd_tpl % (scl, cmd))
7b9b39
+            scl_cmds.append(convert_cmd_scl(scl, cmd))
7b9b39
         self.add_cmd_output(scl_cmds, **kwargs)
7b9b39
 
7b9b39
-    # config files for Software Collections are under /etc/opt/rh/${scl} and
7b9b39
-    # var files are under /var/opt/rh/${scl}. So we need to insert the paths
7b9b39
-    # after the appropriate root dir.
7b9b39
+    # config files for Software Collections are under /etc/${prefix}/${scl} and
7b9b39
+    # var files are under /var/${prefix}/${scl} where the ${prefix} is distro
7b9b39
+    # specific path. So we need to insert the paths after the appropriate root
7b9b39
+    # dir.
7b9b39
     def convert_copyspec_scl(self, scl, copyspec):
7b9b39
+        scl_prefix = self.policy().get_default_scl_prefix()
7b9b39
         for rootdir in ['etc', 'var']:
7b9b39
             p = re.compile('^/%s/' % rootdir)
7b9b39
-            copyspec = p.sub('/%s/opt/rh/%s/' % (rootdir, scl), copyspec)
7b9b39
+            copyspec = p.sub('/%s/%s/%s/' % (rootdir, scl_prefix, scl),
7b9b39
+                             copyspec)
7b9b39
         return copyspec
7b9b39
 
7b9b39
     def add_copy_spec_scl(self, scl, copyspecs):
7b9b39
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
7b9b39
index dffd801c..dc043105 100644
7b9b39
--- a/sos/policies/__init__.py
7b9b39
+++ b/sos/policies/__init__.py
7b9b39
@@ -194,6 +194,7 @@ No changes will be made to system configuration.
7b9b39
     vendor_url = "http://www.example.com/"
7b9b39
     vendor_text = ""
7b9b39
     PATH = ""
7b9b39
+    default_scl_prefix = ""
7b9b39
 
7b9b39
     _in_container = False
7b9b39
     _host_sysroot = '/'
7b9b39
@@ -271,6 +272,9 @@ No changes will be made to system configuration.
7b9b39
             return tempfile.gettempdir()
7b9b39
         return opt_tmp_dir
7b9b39
 
7b9b39
+    def get_default_scl_prefix(self):
7b9b39
+        return self.default_scl_prefix
7b9b39
+
7b9b39
     def match_plugin(self, plugin_classes):
7b9b39
         if len(plugin_classes) > 1:
7b9b39
             for p in plugin_classes:
7b9b39
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
7b9b39
index c7449439..2dfe0589 100644
7b9b39
--- a/sos/policies/redhat.py
7b9b39
+++ b/sos/policies/redhat.py
7b9b39
@@ -44,6 +44,7 @@ class RedHatPolicy(LinuxPolicy):
7b9b39
     _rpmv_filter = ["debuginfo", "-devel"]
7b9b39
     _in_container = False
7b9b39
     _host_sysroot = '/'
7b9b39
+    default_scl_prefix = '/opt/rh'
7b9b39
 
7b9b39
     def __init__(self, sysroot=None):
7b9b39
         super(RedHatPolicy, self).__init__(sysroot=sysroot)
7b9b39
-- 
7b9b39
2.13.6
7b9b39
7b9b39
From 419ebe48ea408b6596ff4d7d9837079dc3057fcf Mon Sep 17 00:00:00 2001
7b9b39
From: Pavel Moravec <pmoravec@redhat.com>
7b9b39
Date: Sat, 25 Nov 2017 12:58:16 +0100
7b9b39
Subject: [PATCH] [postgresql] Call SCL pg_dump with proper path
7b9b39
7b9b39
Also stop storing pg_dump in an auxiliary tempdir but under regular
7b9b39
sos_commands/postgresql directory.
7b9b39
7b9b39
Resolves: #1154
7b9b39
7b9b39
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
7b9b39
---
7b9b39
 sos/plugins/postgresql.py | 43 ++++++++-----------------------------------
7b9b39
 1 file changed, 8 insertions(+), 35 deletions(-)
7b9b39
7b9b39
diff --git a/sos/plugins/postgresql.py b/sos/plugins/postgresql.py
7b9b39
index 45c87e89..9ba696be 100644
7b9b39
--- a/sos/plugins/postgresql.py
7b9b39
+++ b/sos/plugins/postgresql.py
7b9b39
@@ -34,8 +34,6 @@ class PostgreSQL(Plugin):
7b9b39
 
7b9b39
     packages = ('postgresql',)
7b9b39
 
7b9b39
-    tmp_dir = None
7b9b39
-
7b9b39
     password_warn_text = " (password visible in process listings)"
7b9b39
 
7b9b39
     option_list = [
7b9b39
@@ -47,11 +45,9 @@ class PostgreSQL(Plugin):
7b9b39
         ('dbport', 'database server port number', '', '5432')
7b9b39
     ]
7b9b39
 
7b9b39
-    def pg_dump(self, pg_dump_command="pg_dump", filename="sos_pgdump.tar"):
7b9b39
+    def do_pg_dump(self, scl=None, filename="pgdump.tar"):
7b9b39
         if self.get_option("dbname"):
7b9b39
             if self.get_option("password") or "PGPASSWORD" in os.environ:
7b9b39
-                self.tmp_dir = tempfile.mkdtemp()
7b9b39
-                dest_file = os.path.join(self.tmp_dir, filename)
7b9b39
                 # We're only modifying this for ourself and our children so
7b9b39
                 # there is no need to save and restore environment variables if
7b9b39
                 # the user decided to pass the password on the command line.
7b9b39
@@ -59,30 +55,21 @@ class PostgreSQL(Plugin):
7b9b39
                     os.environ["PGPASSWORD"] = str(self.get_option("password"))
7b9b39
 
7b9b39
                 if self.get_option("dbhost"):
7b9b39
-                    cmd = "%s -U %s -h %s -p %s -w -f %s -F t %s" % (
7b9b39
-                        pg_dump_command,
7b9b39
+                    cmd = "pg_dump -U %s -h %s -p %s -w -F t %s" % (
7b9b39
                         self.get_option("username"),
7b9b39
                         self.get_option("dbhost"),
7b9b39
                         self.get_option("dbport"),
7b9b39
-                        dest_file,
7b9b39
                         self.get_option("dbname")
7b9b39
                     )
7b9b39
                 else:
7b9b39
-                    cmd = "%s -C -U %s -w -f %s -F t %s " % (
7b9b39
-                        pg_dump_command,
7b9b39
+                    cmd = "pg_dump -C -U %s -w -F t %s " % (
7b9b39
                         self.get_option("username"),
7b9b39
-                        dest_file,
7b9b39
                         self.get_option("dbname")
7b9b39
                     )
7b9b39
 
7b9b39
-                result = self.call_ext_prog(cmd)
7b9b39
-                if (result['status'] == 0):
7b9b39
-                    self.add_copy_spec(dest_file)
7b9b39
-                else:
7b9b39
-                    self._log_info(
7b9b39
-                        "Unable to execute pg_dump. Error(%s)" %
7b9b39
-                        (result['output'])
7b9b39
-                    )
7b9b39
+                if scl is not None:
7b9b39
+                    cmd = self.convert_cmd_scl(scl, cmd)
7b9b39
+                self.add_cmd_output(cmd, suggest_filename=filename)
7b9b39
             else:  # no password in env or options
7b9b39
                 self.soslog.warning(
7b9b39
                     "password must be supplied to dump a database."
7b9b39
@@ -92,18 +79,7 @@ class PostgreSQL(Plugin):
7b9b39
                 )
7b9b39
 
7b9b39
     def setup(self):
7b9b39
-        self.pg_dump()
7b9b39
-
7b9b39
-    def postproc(self):
7b9b39
-        import shutil
7b9b39
-        if self.tmp_dir:
7b9b39
-            try:
7b9b39
-                shutil.rmtree(self.tmp_dir)
7b9b39
-            except shutil.Error:
7b9b39
-                self.soslog.exception(
7b9b39
-                    "Unable to remove %s." % (self.tmp_dir)
7b9b39
-                )
7b9b39
-                self.add_alert("ERROR: Unable to remove %s." % (self.tmp_dir))
7b9b39
+        self.do_pg_dump()
7b9b39
 
7b9b39
 
7b9b39
 class RedHatPostgreSQL(PostgreSQL, SCLPlugin):
7b9b39
@@ -140,10 +116,7 @@ class RedHatPostgreSQL(PostgreSQL, SCLPlugin):
7b9b39
         )
7b9b39
 
7b9b39
         if scl in self.scls_matched:
7b9b39
-            self.pg_dump(
7b9b39
-                pg_dump_command="scl enable rh-postgresql95 -- pg_dump",
7b9b39
-                filename="sos_scl_pgdump.tar"
7b9b39
-            )
7b9b39
+            self.do_pg_dump(scl=scl, filename="pgdump-scl-%s.tar" % scl)
7b9b39
 
7b9b39
 
7b9b39
 class DebianPostgreSQL(PostgreSQL, DebianPlugin, UbuntuPlugin):
7b9b39
-- 
7b9b39
2.13.6
7b9b39
7b9b39
From 3f0fa8ef20bcc8ec2fb1ff54815141813d07b033 Mon Sep 17 00:00:00 2001
7b9b39
From: Pavel Moravec <pmoravec@redhat.com>
7b9b39
Date: Wed, 20 Dec 2017 11:47:33 +0100
7b9b39
Subject: [PATCH] [plugins] allow add_cmd_output to collect binary output
7b9b39
7b9b39
If a command output is a true binary data, allow add_cmd_output to
7b9b39
collect the raw content and dont try to decode it as UTF-8.
7b9b39
7b9b39
Resolves: #1169
7b9b39
7b9b39
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
7b9b39
---
7b9b39
 sos/archive.py            | 11 ++++++++++
7b9b39
 sos/plugins/__init__.py   | 51 +++++++++++++++++++++++++++++++----------------
7b9b39
 sos/plugins/postgresql.py |  4 +++-
7b9b39
 sos/utilities.py          |  5 +++--
7b9b39
 4 files changed, 51 insertions(+), 20 deletions(-)
7b9b39
7b9b39
diff --git a/sos/archive.py b/sos/archive.py
7b9b39
index 607312a71..80e27b846 100644
7b9b39
--- a/sos/archive.py
7b9b39
+++ b/sos/archive.py
7b9b39
@@ -85,6 +85,9 @@ def add_file(self, src, dest=None):
7b9b39
     def add_string(self, content, dest):
7b9b39
         raise NotImplementedError
7b9b39
 
7b9b39
+    def add_binary(self, content, dest):
7b9b39
+        raise NotImplementedError
7b9b39
+
7b9b39
     def add_link(self, source, link_name):
7b9b39
         raise NotImplementedError
7b9b39
 
7b9b39
@@ -215,6 +218,14 @@ def add_string(self, content, dest):
7b9b39
         self.log_debug("added string at '%s' to FileCacheArchive '%s'"
7b9b39
                        % (src, self._archive_root))
7b9b39
 
7b9b39
+    def add_binary(self, content, dest):
7b9b39
+        dest = self.dest_path(dest)
7b9b39
+        self._check_path(dest)
7b9b39
+        f = codecs.open(dest, 'wb', encoding=None)
7b9b39
+        f.write(content)
7b9b39
+        self.log_debug("added binary content at '%s' to FileCacheArchive '%s'"
7b9b39
+                       % (dest, self._archive_root))
7b9b39
+
7b9b39
     def add_link(self, source, link_name):
7b9b39
         dest = self.dest_path(link_name)
7b9b39
         self._check_path(dest)
7b9b39
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
7b9b39
index 2a8bc516e..0eccd40a1 100644
7b9b39
--- a/sos/plugins/__init__.py
7b9b39
+++ b/sos/plugins/__init__.py
7b9b39
@@ -222,6 +222,11 @@ def do_cmd_private_sub(self, cmd):
7b9b39
             for called in self.executed_commands:
7b9b39
                 if called['file'] is None:
7b9b39
                     continue
7b9b39
+                if called['binary'] == 'yes':
7b9b39
+                    self._log_warn(("Command output '%s' collected as " +
7b9b39
+                                    "binary, output isn't scrubbed despite " +
7b9b39
+                                    "asked for") % called['exe'])
7b9b39
+                    continue
7b9b39
                 if fnmatch.fnmatch(called['exe'], globstr):
7b9b39
                     path = os.path.join(self.commons['cmddir'], called['file'])
7b9b39
                     readable = self.archive.open_file(path)
7b9b39
@@ -260,6 +265,11 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
7b9b39
                 # was anything collected?
7b9b39
                 if called['file'] is None:
7b9b39
                     continue
7b9b39
+                if called['binary'] == 'yes':
7b9b39
+                    self._log_warn(("Command output '%s' collected as " +
7b9b39
+                                    "binary, output isn't scrubbed despite " +
7b9b39
+                                    "asked for") % called['exe'])
7b9b39
+                    continue
7b9b39
                 if fnmatch.fnmatch(called['exe'], globstr):
7b9b39
                     path = os.path.join(self.commons['cmddir'], called['file'])
7b9b39
                     self._log_debug("applying substitution to '%s'" % path)
7b9b39
@@ -587,7 +597,8 @@ def getmtime(path):
7b9b39
                 self.archive.add_link(link_path, _file)
7b9b39
 
7b9b39
     def get_command_output(self, prog, timeout=300, stderr=True,
7b9b39
-                           chroot=True, runat=None, env=None):
7b9b39
+                           chroot=True, runat=None, env=None,
7b9b39
+                           binary=False):
7b9b39
         if chroot or self.commons['cmdlineopts'].chroot == 'always':
7b9b39
             root = self.sysroot
7b9b39
         else:
7b9b39
@@ -595,7 +606,7 @@ def get_command_output(self, prog, timeout=300, stderr=True,
7b9b39
 
7b9b39
         result = sos_get_command_output(prog, timeout=timeout, stderr=stderr,
7b9b39
                                         chroot=root, chdir=runat,
7b9b39
-                                        env=env)
7b9b39
+                                        env=env, binary=binary)
7b9b39
 
7b9b39
         if result['status'] == 124:
7b9b39
             self._log_warn("command '%s' timed out after %ds"
7b9b39
@@ -611,7 +622,8 @@ def get_command_output(self, prog, timeout=300, stderr=True,
7b9b39
                                    % (prog.split()[0], root))
7b9b39
                     return self.get_command_output(prog, timeout=timeout,
7b9b39
                                                    chroot=False, runat=runat,
7b9b39
-                                                   env=env)
7b9b39
+                                                   env=env,
7b9b39
+                                                   binary=binary)
7b9b39
             self._log_debug("could not run '%s': command not found" % prog)
7b9b39
         return result
7b9b39
 
7b9b39
@@ -632,14 +644,14 @@ def check_ext_prog(self, prog):
7b9b39
 
7b9b39
     def _add_cmd_output(self, cmd, suggest_filename=None,
7b9b39
                         root_symlink=None, timeout=300, stderr=True,
7b9b39
-                        chroot=True, runat=None, env=None):
7b9b39
+                        chroot=True, runat=None, env=None, binary=False):
7b9b39
         """Internal helper to add a single command to the collection list."""
7b9b39
         cmdt = (
7b9b39
             cmd, suggest_filename,
7b9b39
             root_symlink, timeout, stderr,
7b9b39
-            chroot, runat, env
7b9b39
+            chroot, runat, env, binary
7b9b39
         )
7b9b39
-        _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s')"
7b9b39
+        _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s', '%s')"
7b9b39
         _logstr = "packed command tuple: " + _tuplefmt
7b9b39
         self._log_debug(_logstr % cmdt)
7b9b39
         self.collect_cmds.append(cmdt)
7b9b39
@@ -647,7 +659,7 @@ def _add_cmd_output(self, cmd, suggest_filename=None,
7b9b39
 
7b9b39
     def add_cmd_output(self, cmds, suggest_filename=None,
7b9b39
                        root_symlink=None, timeout=300, stderr=True,
7b9b39
-                       chroot=True, runat=None, env=None):
7b9b39
+                       chroot=True, runat=None, env=None, binary=False):
7b9b39
         """Run a program or a list of programs and collect the output"""
7b9b39
         if isinstance(cmds, six.string_types):
7b9b39
             cmds = [cmds]
7b9b39
@@ -656,7 +668,7 @@ def add_cmd_output(self, cmds, suggest_filename=None,
7b9b39
         for cmd in cmds:
7b9b39
             self._add_cmd_output(cmd, suggest_filename,
7b9b39
                                  root_symlink, timeout, stderr,
7b9b39
-                                 chroot, runat, env)
7b9b39
+                                 chroot, runat, env, binary)
7b9b39
 
7b9b39
     def get_cmd_output_path(self, name=None, make=True):
7b9b39
         """Return a path into which this module should store collected
7b9b39
@@ -712,14 +724,15 @@ def add_string_as_file(self, content, filename):
7b9b39
 
7b9b39
     def get_cmd_output_now(self, exe, suggest_filename=None,
7b9b39
                            root_symlink=False, timeout=300, stderr=True,
7b9b39
-                           chroot=True, runat=None, env=None):
7b9b39
+                           chroot=True, runat=None, env=None,
7b9b39
+                           binary=False):
7b9b39
         """Execute a command and save the output to a file for inclusion in the
7b9b39
         report.
7b9b39
         """
7b9b39
         start = time()
7b9b39
         result = self.get_command_output(exe, timeout=timeout, stderr=stderr,
7b9b39
                                          chroot=chroot, runat=runat,
7b9b39
-                                         env=env)
7b9b39
+                                         env=env, binary=binary)
7b9b39
         self._log_debug("collected output of '%s' in %s"
7b9b39
                         % (exe.split()[0], time() - start))
7b9b39
 
7b9b39
@@ -729,13 +742,17 @@ def get_cmd_output_now(self, exe, suggest_filename=None,
7b9b39
             outfn = self._make_command_filename(exe)
7b9b39
 
7b9b39
         outfn_strip = outfn[len(self.commons['cmddir'])+1:]
7b9b39
-        self.archive.add_string(result['output'], outfn)
7b9b39
+        if binary:
7b9b39
+            self.archive.add_binary(result['output'], outfn)
7b9b39
+        else:
7b9b39
+            self.archive.add_string(result['output'], outfn)
7b9b39
         if root_symlink:
7b9b39
             self.archive.add_link(outfn, root_symlink)
7b9b39
 
7b9b39
         # save info for later
7b9b39
         # save in our list
7b9b39
-        self.executed_commands.append({'exe': exe, 'file': outfn_strip})
7b9b39
+        self.executed_commands.append({'exe': exe, 'file': outfn_strip,
7b9b39
+                                       'binary': 'yes' if binary else 'no'})
7b9b39
         self.commons['xmlreport'].add_command(cmdline=exe,
7b9b39
                                               exitcode=result['status'],
7b9b39
                                               f_stdout=outfn_strip)
7b9b39
@@ -839,16 +856,16 @@ def _collect_cmd_output(self):
7b9b39
                 timeout,
7b9b39
                 stderr,
7b9b39
                 chroot, runat,
7b9b39
-                env
7b9b39
+                env, binary
7b9b39
             ) = progs[0]
7b9b39
-            self._log_debug("unpacked command tuple: " +
7b9b39
-                            "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s')" %
7b9b39
-                            progs[0])
7b9b39
+            self._log_debug(("unpacked command tuple: " +
7b9b39
+                             "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s'," +
7b9b39
+                             "'%s')") % progs[0])
7b9b39
             self._log_info("collecting output of '%s'" % prog)
7b9b39
             self.get_cmd_output_now(prog, suggest_filename=suggest_filename,
7b9b39
                                     root_symlink=root_symlink, timeout=timeout,
7b9b39
                                     stderr=stderr, chroot=chroot, runat=runat,
7b9b39
-                                    env=env)
7b9b39
+                                    env=env, binary=binary)
7b9b39
 
7b9b39
     def _collect_strings(self):
7b9b39
         for string, file_name in self.copy_strings:
7b9b39
diff --git a/sos/plugins/postgresql.py b/sos/plugins/postgresql.py
7b9b39
index 9ba696be2..2e330c9b5 100644
7b9b39
--- a/sos/plugins/postgresql.py
7b9b39
+++ b/sos/plugins/postgresql.py
7b9b39
@@ -69,7 +69,9 @@ def do_pg_dump(self, scl=None, filename="pgdump.tar"):
7b9b39
 
7b9b39
                 if scl is not None:
7b9b39
                     cmd = self.convert_cmd_scl(scl, cmd)
7b9b39
-                self.add_cmd_output(cmd, suggest_filename=filename)
7b9b39
+                self.add_cmd_output(cmd, suggest_filename=filename,
7b9b39
+                                    binary=True)
7b9b39
+
7b9b39
             else:  # no password in env or options
7b9b39
                 self.soslog.warning(
7b9b39
                     "password must be supplied to dump a database."
7b9b39
diff --git a/sos/utilities.py b/sos/utilities.py
7b9b39
index 55bb1dc96..b5aa571b7 100644
7b9b39
--- a/sos/utilities.py
7b9b39
+++ b/sos/utilities.py
7b9b39
@@ -110,7 +110,8 @@ def is_executable(command):
7b9b39
 
7b9b39
 
7b9b39
 def sos_get_command_output(command, timeout=300, stderr=False,
7b9b39
-                           chroot=None, chdir=None, env=None):
7b9b39
+                           chroot=None, chdir=None, env=None,
7b9b39
+                           binary=False):
7b9b39
     """Execute a command and return a dictionary of status and output,
7b9b39
     optionally changing root or current working directory before
7b9b39
     executing command.
7b9b39
@@ -164,7 +165,7 @@ def _child_prep_fn():
7b9b39
 
7b9b39
     return {
7b9b39
         'status': p.returncode,
7b9b39
-        'output': stdout.decode('utf-8', 'ignore')
7b9b39
+        'output': stdout if binary else stdout.decode('utf-8', 'ignore')
7b9b39
     }
7b9b39
 
7b9b39