Refactor dump compression and use get_bin_path for finding the compressors

reviewable/pr18780/r1
Toshio Kuratomi 10 years ago
parent 29f4a5a1ed
commit 32e609720a

@ -142,14 +142,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

Loading…
Cancel
Save