def restore(database_name, data): from trytond.tools import exec_pg_command_pipe database = Database().connect() cursor = database.cursor(autocommit=True) database.create(cursor, database_name) cursor.commit() cursor.close() cmd = ['mysql'] if CONFIG['db_user']: cmd.append('--user='******'db_user']) if CONFIG['db_host']: cmd.append('--host=' + CONFIG['db_host']) if CONFIG['db_port']: cmd.append('--port=' + CONFIG['db_port']) if CONFIG['db_password']: cmd.append('--password='******'db_password']) cmd.append(database_name) fd, file_name = tempfile.mkstemp() with os.fdopen(fd, 'wb+') as fd: fd.write(data) cmd.append('<') cmd.append(file_name) args2 = tuple(cmd) pipe = exec_pg_command_pipe(*args2) pipe.stdin.close() res = pipe.wait() os.remove(file_name) if res: raise Exception('Couldn\'t restore database') database = Database(database_name).connect() cursor = database.cursor() if not cursor.test(): cursor.close() database.close() raise Exception('Couldn\'t restore database!') cursor.close() database.close() Database._list_cache = None return True
def restore(database_name, data): from trytond.tools import exec_pg_command_pipe database = Database().connect() cursor = database.cursor(autocommit=True) database.create(cursor, database_name) cursor.commit() cursor.close() cmd = ["pg_restore", "--no-owner"] if CONFIG["db_user"]: cmd.append("--username="******"db_user"]) if CONFIG["db_host"]: cmd.append("--host=" + CONFIG["db_host"]) if CONFIG["db_port"]: cmd.append("--port=" + CONFIG["db_port"]) cmd.append("--dbname=" + database_name) args2 = tuple(cmd) if os.name == "nt": tmpfile = (os.environ["TMP"] or "C:\\") + os.tmpnam() with open(tmpfile, "wb") as fp: fp.write(data) args2 = list(args2) args2.append(" " + tmpfile) args2 = tuple(args2) pipe = exec_pg_command_pipe(*args2) if not os.name == "nt": pipe.stdin.write(data) pipe.stdin.close() res = pipe.wait() if res: raise Exception("Couldn't restore database") database = Database(database_name).connect() cursor = database.cursor() if not cursor.test(): cursor.close() database.close() raise Exception("Couldn't restore database!") cursor.close() database.close() Database._list_cache = None return True
def restore(database_name, data): from trytond.tools import exec_pg_command_pipe database = Database().connect() cursor = database.cursor(autocommit=True) database.create(cursor, database_name) cursor.commit() cursor.close() cmd = ['pg_restore', '--no-owner'] if CONFIG['db_user']: cmd.append('--username='******'db_user']) if CONFIG['db_host']: cmd.append('--host=' + CONFIG['db_host']) if CONFIG['db_port']: cmd.append('--port=' + CONFIG['db_port']) cmd.append('--dbname=' + database_name) args2 = tuple(cmd) if os.name == "nt": tmpfile = (os.environ['TMP'] or 'C:\\') + os.tmpnam() with open(tmpfile, 'wb') as fp: fp.write(data) args2 = list(args2) args2.append(' ' + tmpfile) args2 = tuple(args2) pipe = exec_pg_command_pipe(*args2) if not os.name == "nt": pipe.stdin.write(data) pipe.stdin.close() res = pipe.wait() if res: raise Exception('Couldn\'t restore database') database = Database(database_name).connect() cursor = database.cursor() if not cursor.test(): cursor.close() database.close() raise Exception('Couldn\'t restore database!') cursor.close() database.close() Database._list_cache = None return True
def dump(database_name): from trytond.tools import exec_pg_command_pipe cmd = ["pg_dump", "--format=c", "--no-owner"] if CONFIG["db_user"]: cmd.append("--username="******"db_user"]) if CONFIG["db_host"]: cmd.append("--host=" + CONFIG["db_host"]) if CONFIG["db_port"]: cmd.append("--port=" + CONFIG["db_port"]) cmd.append(database_name) pipe = exec_pg_command_pipe(*tuple(cmd)) pipe.stdin.close() data = pipe.stdout.read() res = pipe.wait() if res: raise Exception("Couldn't dump database!") return data
def dump(database_name): from trytond.tools import exec_pg_command_pipe cmd = ['pg_dump', '--format=c', '--no-owner'] if CONFIG['db_user']: cmd.append('--username='******'db_user']) if CONFIG['db_host']: cmd.append('--host=' + CONFIG['db_host']) if CONFIG['db_port']: cmd.append('--port=' + CONFIG['db_port']) cmd.append(database_name) pipe = exec_pg_command_pipe(*tuple(cmd)) pipe.stdin.close() data = pipe.stdout.read() res = pipe.wait() if res: raise Exception('Couldn\'t dump database!') return data