Merge pull request #824 from Jmainguy/mysql_db_616

Now correctly gzip/bzips file back up in case of import failure
reviewable/pr18780/r1
Toshio Kuratomi 10 years ago
commit ec6304d5a0

@ -152,39 +152,39 @@ def db_import(module, host, user, password, db_name, target, port, socket=None):
cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port)) cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port))
cmd += " -D %s" % pipes.quote(db_name) cmd += " -D %s" % pipes.quote(db_name)
if os.path.splitext(target)[-1] == '.gz': if os.path.splitext(target)[-1] == '.gz':
gunzip_path = module.get_bin_path('gunzip') gzip_path = module.get_bin_path('gzip')
if gunzip_path: if not gzip_path:
rc, stdout, stderr = module.run_command('%s %s' % (gunzip_path, target)) module.fail_json(msg="gzip command not found")
if rc != 0: #gzip -d file (uncompress)
return rc, stdout, stderr rc, stdout, stderr = module.run_command('%s -d %s' % (gzip_path, target))
cmd += " < %s" % pipes.quote(os.path.splitext(target)[0]) if rc != 0:
return rc, stdout, stderr
#Import sql
cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
try:
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0: if rc != 0:
return rc, stdout, stderr return rc, stdout, stderr
gzip_path = module.get_bin_path('gzip') finally:
if gzip_path: #gzip file back up
rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, os.path.splitext(target)[0])) module.run_command('%s %s' % (gzip_path, os.path.splitext(target)[0]))
else:
module.fail_json(msg="gzip command not found")
else:
module.fail_json(msg="gunzip command not found")
elif os.path.splitext(target)[-1] == '.bz2': elif os.path.splitext(target)[-1] == '.bz2':
bunzip2_path = module.get_bin_path('bunzip2') bzip2_path = module.get_bin_path('bzip2')
if bunzip2_path: if not bzip2_path:
rc, stdout, stderr = module.run_command('%s %s' % (bunzip2_path, target)) module.fail_json(msg="bzip2 command not found")
if rc != 0: #bzip2 -d file (uncompress)
return rc, stdout, stderr rc, stdout, stderr = module.run_command('%s -d %s' % (bzip2_path, target))
cmd += " < %s" % pipes.quote(os.path.splitext(target)[0]) if rc != 0:
return rc, stdout, stderr
#Import sql
cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
try:
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0: if rc != 0:
return rc, stdout, stderr return rc, stdout, stderr
bzip2_path = module.get_bin_path('bzip2') finally:
if bzip2_path: #bzip2 file back up
rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, os.path.splitext(target)[0])) rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, os.path.splitext(target)[0]))
else:
module.fail_json(msg="bzip2 command not found")
else:
module.fail_json(msg="bunzip2 command not found")
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)

Loading…
Cancel
Save