mysql_db now supports import and dump of gzip and bzip2 compressed files

This commit is contained in:
Damian Moore 2013-09-30 19:09:32 +01:00
parent 9b5fb9ad6b
commit 3c57168aaa

View file

@ -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):