Exemplo n.º 1
0
 def backup(self):
     logging.debug("DB Backup started")
     #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting  --disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\
     #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, self.sqlfile, basedefs.DB_NAME)
     cmd = [
         basedefs.EXEC_PGDUMP,
         "-C",
         "-E",
         "UTF8",
         "--disable-dollar-quoting",
         "--disable-triggers",
         "-U",
         SERVER_ADMIN,
         "-h",
         SERVER_NAME,
         "-p",
         SERVER_PORT,
         "--format=p",
         "-f",
         self.sqlfile,
         basedefs.DB_NAME,
     ]
     output, rc = utils.execCmd(cmdList=cmd,
                                failOnError=True,
                                msg=MSG_ERROR_BACKUP_DB,
                                envDict=utils.getPgPassEnv())
     logging.debug("DB Backup completed successfully")
Exemplo n.º 2
0
    def restore(self):
        # run psql -U engine -h host -p port -d template1 -f <backup directory>/<backup_file>
        # If DB was renamed, restore it

        if self.updated or self.dbrenamed:
            logging.debug("DB Restore started")

            # If we're here, upgrade failed. Drop temp DB.
            cmd = [
                basedefs.EXEC_DROPDB,
                "-U",
                SERVER_ADMIN,
                "-h",
                SERVER_NAME,
                "-p",
                SERVER_PORT,
                self.name,
            ]
            output, rc = utils.execCmd(cmdList=cmd,
                                       failOnError=True,
                                       msg=MSG_ERROR_DROP_DB,
                                       envDict=utils.getPgPassEnv())

            # Restore
            cmd = [
                basedefs.EXEC_PSQL,
                "-U",
                SERVER_ADMIN,
                "-h",
                SERVER_NAME,
                "-p",
                SERVER_PORT,
                "-d",
                basedefs.DB_TEMPLATE,
                "-f",
                self.sqlfile,
            ]
            output, rc = utils.execCmd(cmdList=cmd,
                                       failOnError=True,
                                       msg=MSG_ERROR_RESTORE_DB,
                                       envDict=utils.getPgPassEnv())
            logging.debug("DB Restore completed successfully")
        else:
            logging.debug("No DB Restore needed")
Exemplo n.º 3
0
def deployDbAsyncTasks(dbName=basedefs.DB_NAME):
    # Deploy DB functionality first
    cmd = [
        basedefs.EXEC_PSQL,
        "-U",
        SERVER_ADMIN,
        "-f",
        basedefs.FILE_DB_ASYNC_TASKS,
        "-d",
        dbName,
    ]

    out, rc = utils.execCmd(cmdList=cmd,
                            failOnError=True,
                            msg="Error updating DB for getting async_tasks",
                            envDict=utils.getPgPassEnv())
Exemplo n.º 4
0
 def __init__(self):
     self.sqlfile = tempfile.mkstemp(suffix=".sql",
                                     dir=basedefs.DIR_DB_BACKUPS)[1]
     self.dropped = False
     self.env = utils.getPgPassEnv()
Exemplo n.º 5
0
    def restore(self):
        # run psql -U engine -h host -p port -d template1 -f <backup directory>/<backup_file>
        # If DB was renamed, restore it

        if self.updated or self.dbrenamed:
            logging.debug("DB Restore started")

            # If we're here, upgrade failed. Drop temp DB.
            cmd = [
                basedefs.EXEC_DROPDB,
                "-U", SERVER_ADMIN,
                "-h", SERVER_NAME,
                "-p", SERVER_PORT,
                self.name,
            ]
            output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_DROP_DB)

            # Restore
            cmd = [
                basedefs.EXEC_PSQL,
                "-U", SERVER_ADMIN,
                "-h", SERVER_NAME,
                "-p", SERVER_PORT,
                "-d", basedefs.DB_TEMPLATE,
                "-f", self.sqlfile,
            ]
            output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_RESTORE_DB, envDict=utils.getPgPassEnv())
            logging.debug("DB Restore completed successfully")
        else:
            logging.debug("No DB Restore needed")
Exemplo n.º 6
0
 def backup(self):
     logging.debug("DB Backup started")
     #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting  --disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\
         #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, self.sqlfile, basedefs.DB_NAME)
     cmd = [
         basedefs.EXEC_PGDUMP,
         "-C", "-E", "UTF8",
         "--disable-dollar-quoting",
         "--disable-triggers",
         "-U", SERVER_ADMIN,
         "-h", SERVER_NAME,
         "-p", SERVER_PORT,
         "--format=p",
         "-f", self.sqlfile,
         basedefs.DB_NAME,
     ]
     output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_BACKUP_DB, envDict=utils.getPgPassEnv())
     logging.debug("DB Backup completed successfully")
Exemplo n.º 7
0
 def __init__(self):
     self.sqlfile = tempfile.mkstemp(suffix=".sql", dir=basedefs.DIR_DB_BACKUPS)[1]
     self.dropped = False
     self.env = utils.getPgPassEnv()