def get_names(user, passwd, host="localhost", ignore=None): cmd = 'mysql -u%s -p%s --batch -e "SHOW DATABASES" -h %s ' % (user, passwd, host) output = lrun(cmd) if is_force_local(): separator = "\n" else: separator = "\r\n" db_names = output.split(separator)[1:] if ignore is not None: for name in ignore: if name in db_names: db_names.remove(name) return db_names
def dump(dbname, user, passwd, host="localhost"): filename = "%s_%s.sql" % (dbname, datetime.now().strftime("%Y%m%d_%H%M%S")) destination = "%s/mysql" % (get_backup_dir(),) lrun("mkdir -p %s" % (destination,)) lrun("mysqldump -h %s -u %s -p%s %s > %s/%s" % (host, user, passwd, dbname, destination, filename))
def backup(): lrun("whoami")