Exemple #1
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))

        # Force the checkpoint - WAL mechanism
        cmd = "{sqlite_cmd} {path}/{db} 'PRAGMA wal_checkpoint(PASSIVE);'".format(
            sqlite_cmd=self._backup_lib.SQLITE_SQLITE,
            path=self._backup_lib.dir_foglamp_data,
            db=self._backup_lib.config['database-filename'])

        # 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'])

        # Prepares the backup command
        cmd = "{sqlite_cmd} {path}/{db} '{backup_cmd} {file}'".format(
            sqlite_cmd=self._backup_lib.SQLITE_SQLITE,
            path=self._backup_lib.dir_foglamp_data,
            db=self._backup_lib.config['database-filename'],
            backup_cmd=self._backup_lib.SQLITE_BACKUP,
            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
Exemple #2
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
Exemple #3
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
        cmd = "{cmd} {file} {path}/{db} ".format(
            cmd=self._restore_lib.SQLITE_RESTORE,
            file=backup_file,
            path=self._restore_lib.dir_foglamp_data,
            db=self._restore_lib.config['database-filename'])

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

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

        if status != 0:
            raise exceptions.RestoreFailed
Exemple #4
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)