示例#1
0
    def _foglamp_start(self):
        """ Starts FogLAMP after the execution of the restore

        Args:
        Returns:
        Raises:
            FogLAMPStartError
        """

        cmd = "{path}/{cmd}".format(
                                    path=self._restore_lib.dir_foglamp_root,
                                    cmd=self._foglamp_cmd.format("start")
        )

        exit_code, output = lib.exec_wait_retry(
                                                cmd,
                                                True,
                                                max_retry=self._restore_lib.config['max_retry'],
                                                timeout=self._restore_lib.config['timeout'])

        self._logger.debug("{func} - exit_code |{exit_code}| - cmd |{cmd}| - output |{output}|".format(
                                    func="_foglamp_start",
                                    exit_code=exit_code,
                                    cmd=cmd,
                                    output=output))

        if exit_code == 0:
            if self._check_wait_foglamp_start() != self.FogLampStatus.RUNNING:
                raise exceptions.FogLAMPStartError

        else:
            raise exceptions.FogLAMPStartError
示例#2
0
    def _foglamp_stop(self):
        """ Stops FogLAMP before for the execution of the backup, doing a cold backup

        Args:
        Returns:
        Raises:
            FogLAMPStopError
        """

        self._logger.debug("{func}".format(func="_foglamp_stop"))

        cmd = "{path}/{cmd}".format(
            path=self._restore_lib.dir_foglamp_root,
            cmd=self._foglamp_cmd.format("stop")
        )

        # Stops FogLamp
        status, output = lib.exec_wait_retry(cmd, True,
                                             max_retry=self._restore_lib.config['max_retry'],
                                             timeout=self._restore_lib.config['timeout'])

        self._logger.debug("{func} - status |{status}| - cmd |{cmd}| - output |{output}|   ".format(
                    func="_foglamp_stop",
                    status=status,
                    cmd=cmd,
                    output=output))

        if status == 0:

            # Checks to ensure the FogLamp status
            if self._foglamp_status() != self.FogLampStatus.STOPPED:
                raise exceptions.FogLAMPStopError(output)
        else:
            raise exceptions.FogLAMPStopError(output)
示例#3
0
    def _run_backup_command(self, _backup_file):
        """ Backups the entire FogLAMP repository into a file in the local file system

        Args:
            _backup_file: backup file to create  as a full path
        Returns:
            _status: status of the backup
            _exit_code: exit status of the operation, 0=Successful
        Raises:
        """

        self._logger.debug("{func} - file_name |{file}|".format(
            func="_run_backup_command", file=_backup_file))

        pg_cmd = self._backup_lib.PG_COMMANDS[self._backup_lib.PG_COMMAND_DUMP]

        # Prepares the backup command
        cmd = "{cmd} {options} {db} > {file}".format(
            cmd=pg_cmd,
            options="--serializable-deferrable -Fc",
            db=self._backup_lib.config['database'],
            file=_backup_file)

        # Executes the backup waiting for the completion and using a retry mechanism
        # noinspection PyArgumentEqualDefault
        _exit_code, output = lib.exec_wait_retry(
            cmd,
            output_capture=True,
            exit_code_ok=0,
            max_retry=self._backup_lib.config['max_retry'],
            timeout=self._backup_lib.config['timeout'])

        if _exit_code == 0:
            _status = lib.BackupStatus.COMPLETED
        else:
            _status = lib.BackupStatus.FAILED

        self._logger.debug(
            "{func} - status |{status}| - exit_code |{exit_code}| "
            "- cmd |{cmd}|  output |{output}| ".format(
                func="_run_backup_command",
                status=_status,
                exit_code=_exit_code,
                cmd=cmd,
                output=output))

        return _status, _exit_code
示例#4
0
    def _exec_backup(self, _backup_file):
        """ Backups the entire FogLAMP repository into a file in the local file system

        Args:
            _backup_file: backup file to create  as a full path
        Returns:
            _status: status of the backup
            _exit_code: exit status of the operation, 0=Successful
        Raises:
        """

        self._logger.debug("{func} - file_name |{file}|".format(
            func="_exec_backup", file=_backup_file))

        # Prepares the backup command
        cmd = "pg_dump"
        cmd += " --serializable-deferrable -Fc  "
        cmd += " -h {host} -p {port} {db} > {file}".format(
            host=self._config['host'],
            port=self._config['port'],
            db=self._config['database'],
            file=_backup_file)

        # Executes the backup waiting for the completion and using a retry mechanism
        # noinspection PyArgumentEqualDefault
        _exit_code, output = lib.exec_wait_retry(
            cmd,
            output_capture=True,
            exit_code_ok=0,
            max_retry=self._config['max_retry'],
            timeout=self._config['timeout'])

        if _exit_code == 0:
            _status = lib.BACKUP_STATUS_SUCCESSFUL
        else:
            _status = lib.BACKUP_STATUS_FAILED

        self._logger.debug(
            "{func} - status |{status}| - exit_code |{exit_code}| "
            "- cmd |{cmd}|  output |{output}| ".format(func="_exec_backup",
                                                       status=_status,
                                                       exit_code=_exit_code,
                                                       cmd=cmd,
                                                       output=output))

        return _status, _exit_code
示例#5
0
    def _run_restore_command(self, backup_file):
        """ Executes the restore of the storage layer from a backup

        Args:
            backup_file: backup file to restore
        Returns:
        Raises:
            RestoreError
        """

        self._logger.debug("{func} - Restore starts - file name |{file}|".format(
                                                                    func="_run_restore_command",
                                                                    file=backup_file))

        # Prepares the restore command
        pg_cmd = self._restore_lib.PG_COMMANDS[self._restore_lib.PG_COMMAND_RESTORE]

        cmd = "{cmd} {options} {schema} -d {db}  {file}".format(
                                                cmd=pg_cmd,
                                                options="--verbose --clean -n ",
                                                schema=self._restore_lib.config['schema'],
                                                db=self._restore_lib.config['database'],
                                                file=backup_file
        )

        # Restores the backup
        status, output = lib.exec_wait_retry(cmd, True, timeout=self._restore_lib.config['timeout'])

        # Avoid output too long
        output_short = output.splitlines()[10]

        self._logger.debug("{func} - Restore ends - status |{status}| - cmd |{cmd}| - output |{output}|".format(
                                    func="_run_restore_command",
                                    status=status,
                                    cmd=cmd,
                                    output=output_short))

        if status != 0:
            raise exceptions.RestoreFailed