diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-05-25 09:22:08 -0700 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-05-27 20:31:51 -0700 |
commit | 579ba51240d8de0743d43746c6780d5d279bee63 (patch) | |
tree | b374fe871cc6a64ac310ec4d84f7911fee16b6d3 | |
parent | 95ea893bc308a76b15128688afc603d5751904b2 (diff) | |
download | ansible-modules-core-579ba51240d8de0743d43746c6780d5d279bee63.tar.gz |
Refactor dump compression and use get_bin_path for finding the compressors
-rw-r--r-- | database/mysql/mysql_db.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py index b28ef219..0cf0ea5c 100644 --- a/database/mysql/mysql_db.py +++ b/database/mysql/mysql_db.py @@ -143,14 +143,20 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port, cmd += " --all-databases" else: cmd += " %s" % pipes.quote(db_name) + + path = None if os.path.splitext(target)[-1] == '.gz': - cmd = cmd + ' | gzip > ' + pipes.quote(target) + path = module.get_bin_path('gzip', True) elif os.path.splitext(target)[-1] == '.bz2': - cmd = cmd + ' | bzip2 > ' + pipes.quote(target) + path = module.get_bin_path('bzip2', True) elif os.path.splitext(target)[-1] == '.xz': - cmd = cmd + ' | xz > ' + pipes.quote(target) + path = module.get_bin_path('xz', True) + + if path: + cmd = '%s | %s > %s' % (cmd, path, pipes.quote(target)) else: cmd += " > %s" % pipes.quote(target) + rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) return rc, stdout, stderr |