1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #4307 from damianmoore/mysql_gzip_bzip2_support

Add support for compressing mysql dumps and extracting during import.
This commit is contained in:
James Tanner 2013-11-07 15:07:59 -05:00
commit 6cdc99286c

View file

@ -124,6 +124,11 @@ def db_dump(module, host, user, password, db_name, target, socket=None):
else: else:
cmd += " --host=%s" % host cmd += " --host=%s" % host
cmd += " %s" % db_name cmd += " %s" % db_name
if os.path.splitext(target)[-1] == '.gz':
cmd = cmd + ' | gzip > ' + target
elif os.path.splitext(target)[-1] == '.bz2':
cmd = cmd + ' | bzip2 > ' + target
else:
cmd += " > %s" % target cmd += " > %s" % target
rc, stdout, stderr = module.run_command(cmd) rc, stdout, stderr = module.run_command(cmd)
return rc, stdout, stderr return rc, stdout, stderr
@ -136,6 +141,11 @@ def db_import(module, host, user, password, db_name, target, socket=None):
else: else:
cmd += " --host=%s" % host cmd += " --host=%s" % host
cmd += " -D %s" % db_name cmd += " -D %s" % db_name
if os.path.splitext(target)[-1] == '.gz':
cmd = 'gunzip < ' + target + ' | ' + cmd
elif os.path.splitext(target)[-1] == '.bz2':
cmd = 'bunzip2 < ' + target + ' | ' + cmd
else:
cmd += " < %s" % target cmd += " < %s" % target
rc, stdout, stderr = module.run_command(cmd) rc, stdout, stderr = module.run_command(cmd)
return rc, stdout, stderr return rc, stdout, stderr