From 3c57168aaa3d52262a56766941576fe502eee84b Mon Sep 17 00:00:00 2001 From: Damian Moore Date: Mon, 30 Sep 2013 19:09:32 +0100 Subject: [PATCH] mysql_db now supports import and dump of gzip and bzip2 compressed files --- library/database/mysql_db | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/library/database/mysql_db b/library/database/mysql_db index e33dba4caa..7dc7220237 100644 --- a/library/database/mysql_db +++ b/library/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):