diff options
author | Stephanie Marcu <stephanie.marcu@logilab.fr> | 2009-04-27 13:01:34 +0200 |
---|---|---|
committer | Stephanie Marcu <stephanie.marcu@logilab.fr> | 2009-04-27 13:01:34 +0200 |
commit | b2e0751958e39d5ce57ce16468872c495accce94 (patch) | |
tree | c2708206223a5cb23699cb954a64cd6cc403fb9d | |
parent | 6e6223100ab09970d0fe538add5c14163b8b8a38 (diff) | |
download | logilab-common-b2e0751958e39d5ce57ce16468872c495accce94.tar.gz |
don't add -h option if dbhost is None
-rw-r--r-- | adbh.py | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -470,20 +470,26 @@ class _MyAdvFuncHelper(_GenericAdvFuncHelper): keepownership=True): """return a command to backup the given database""" # XXX compress - return 'mysqldump -h %s -u %s -p -r %s %s' % (dbhost, dbuser, backupfile, dbname) + host_option = '' + if dbhost is not None: + host_option = '-h %s' % dbhost + return 'mysqldump %s -u %s -p -r %s %s' % (host_option, dbuser, backupfile, dbname) def restore_commands(self, dbname, dbhost, dbuser, backupfile, encoding='utf-8', keepownership=True, drop=True): """return a list of commands to restore a backup the given database""" cmds = [] + host_option = '' + if dbhost is not None: + host_option = '-h %s' % dbhost if drop: - cmd = 'echo "DROP DATABASE %s;" | mysql -h %s -u %s -p' % ( - dbname, dbhost, dbuser) + cmd = 'echo "DROP DATABASE %s;" | mysql %s -u %s -p' % ( + dbname, host_option, dbuser) cmds.append(cmd) - cmd = 'echo "%s;" | mysql -h %s -u %s -p' % ( - self.sql_create_database(dbname, encoding), dbhost, dbuser) + cmd = 'echo "%s;" | mysql %s -u %s -p' % ( + self.sql_create_database(dbname, encoding), host_option, dbuser) cmds.append(cmd) - cmd = 'mysql -h %s -u %s -p %s < %s' % (dbhost, dbuser, dbname, backupfile) + cmd = 'mysql %s -u %s -p %s < %s' % (host_option, dbuser, dbname, backupfile) cmds.append(cmd) return cmds |