mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Refactor dump compression and use get_bin_path for finding the compressors
This commit is contained in:
parent
aa79810cc8
commit
dd4838e4aa
1 changed files with 9 additions and 3 deletions
|
@ -143,14 +143,20 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
|
||||||
cmd += " --all-databases"
|
cmd += " --all-databases"
|
||||||
else:
|
else:
|
||||||
cmd += " %s" % pipes.quote(db_name)
|
cmd += " %s" % pipes.quote(db_name)
|
||||||
|
|
||||||
|
path = None
|
||||||
if os.path.splitext(target)[-1] == '.gz':
|
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':
|
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':
|
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:
|
else:
|
||||||
cmd += " > %s" % pipes.quote(target)
|
cmd += " > %s" % pipes.quote(target)
|
||||||
|
|
||||||
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
|
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
|
||||||
return rc, stdout, stderr
|
return rc, stdout, stderr
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue