diff --git a/database/mysql_db b/database/mysql_db index e33dba4caac..7dc72202379 100644 --- a/database/mysql_db +++ b/database/mysql_db @@ -117,15 +117,25 @@ def db_delete(cursor, db): return True def db_dump(host, user, password, db_name, target): - res = os.system("/usr/bin/mysqldump -q -h "+host+" -u "+user+ " --password="+password+" " - +db_name+" > " - +target) + cmd = '/usr/bin/mysqldump -q -h ' + host + ' -u ' + user + ' --password=' + password + ' ' + 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 = cmd + ' > ' + target + res = os.system(cmd) return (res == 0) def db_import(host, user, password, db_name, target): - res = os.system("/usr/bin/mysql -h "+host+" -u "+user+" --password="+password+" " - +db_name+" < " - +target) + cmd = '/usr/bin/mysql -h ' + host + ' -u ' + user + ' --password=' + password + ' ' + 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 = cmd + ' < ' + target + res = os.system(cmd) return (res == 0) def db_create(cursor, db, encoding, collation):