diff --git a/py/webnotes/model/db_schema.py b/py/webnotes/model/db_schema.py index e1e02058d2..eb9f73f36f 100644 --- a/py/webnotes/model/db_schema.py +++ b/py/webnotes/model/db_schema.py @@ -357,8 +357,11 @@ class DbManager: mysql_path = getattr(webnotes.defs, 'mysql_path', None) mysql = mysql_path and os.path.join(mysql_path, 'mysql') or 'mysql' + from webnotes.utils import make_esc + esc = make_esc('$ ') + try: - ret = os.system("%s -u root -p%s %s < %s"%(mysql, root_password.replace(" ", "\ "), target.replace("$", "\$"), source)) + ret = os.system("%s -u root -p%s %s < %s"%(mysql, esc(root_password), esc(target), source)) except Exception,e: raise e diff --git a/py/webnotes/utils/__init__.py b/py/webnotes/utils/__init__.py index 6e342f1802..b3d044d7dd 100644 --- a/py/webnotes/utils/__init__.py +++ b/py/webnotes/utils/__init__.py @@ -636,6 +636,10 @@ def get_file_timestamp(fn): else: return None - +def make_esc(esc_chars): + """ + Function generator for Escaping special characters + """ + return lambda s: ''.join(['\\' + c if c in esc_chars else c for c in s]) diff --git a/py/webnotes/utils/backups.py b/py/webnotes/utils/backups.py index 26e1f98771..5c74ffe618 100644 --- a/py/webnotes/utils/backups.py +++ b/py/webnotes/utils/backups.py @@ -24,11 +24,11 @@ class BackupGenerator: If specifying db_file_name, also append ".sql.gz" """ def __init__(self, db_name, user, password, db_file_name=None): - self.db_name = db_name + self.db_name = db_name.replace('$', '\$') self.user = user self.password = password self.db_file_name = db_file_name and db_file_name \ - or (os.path.join(backup_path, db_name + ".sql.gz")) + or (os.path.join(backup_path, self.db_name + ".sql.gz")) def take_dump(self): """ @@ -88,7 +88,7 @@ class BackupGenerator: Also, a new backup will be available for download (if requested)\ only after 24 hours.""" % {"file_url":file_url} - datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name).st_ctime) + datetime_str = datetime.fromtimestamp(os.stat(self.db_file_name.replace('\$', '$')).st_ctime) subject = datetime_str.strftime("%d/%m/%Y %H:%M:%S") + """ - Backup ready to be downloaded""" sendmail(recipients=recipient_list, msg=msg, subject=subject)