Beispiel #1
0
    def restore(self, backup, restore_path, overwrite):
        """
        :type backup: freezer.storage.Backup
        """
        logging.info("Creation restore path: {0}".format(restore_path))
        utils.create_dir_tree(restore_path)
        if not overwrite and not utils.is_empty_dir(restore_path):
            raise Exception(
                "Restore dir is not empty. "
                "Please use --overwrite or provide different path.")
        logging.info("Creation restore path completed")
        for level in range(0, backup.level + 1):
            b = backup.full_backup.increments[level]
            logging.info("Restore backup {0}".format(b))
            read_pipe, write_pipe = multiprocessing.Pipe()
            process_stream = multiprocessing.Process(
                target=self.read_blocks,
                args=(b, write_pipe, read_pipe))
            process_stream.daemon = True
            process_stream.start()
            write_pipe.close()

            # Start the tar pipe consumer process
            tar_stream = multiprocessing.Process(
                target=self.restore_level,
                args=(restore_path, read_pipe, backup))
            tar_stream.daemon = True
            tar_stream.start()
            read_pipe.close()
            write_pipe.close()
            process_stream.join()
            tar_stream.join()

            if tar_stream.exitcode:
                raise Exception('failed to restore file')

        logging.info(
            '[*] Restore execution successfully executed \
             for backup name {0}'.format(backup))
Beispiel #2
0
 def create_dirs(self, path):
     utils.create_dir_tree(path)
Beispiel #3
0
    def restore(self, hostname_backup_name, restore_resource,
                overwrite,
                recent_to_date,
                backup_media=None):
        """

        :param hostname_backup_name:
        :param restore_path:
        :param overwrite:
        :param recent_to_date:
        """
        if backup_media == 'fs':
            LOG.info("Creating restore path: {0}".format(restore_resource))
            # if restore path can't be created this function will raise
            # exception
            utils.create_dir_tree(restore_resource)
            if not overwrite and not utils.is_empty_dir(restore_resource):
                raise Exception(
                    "Restore dir is not empty. "
                    "Please use --overwrite or provide different path "
                    "or remove the content of {}".format(restore_resource))

            LOG.info("Restore path creation completed")

        backups = self.storage.get_latest_level_zero_increments(
            engine=self,
            hostname_backup_name=hostname_backup_name,
            recent_to_date=recent_to_date)

        max_level = max(backups.keys())

        # Use SimpleQueue because Queue does not work on Mac OS X.
        read_except_queue = queues.SimpleQueue()
        LOG.info("Restoring backup {0}".format(hostname_backup_name))
        for level in range(0, max_level + 1):
            LOG.info("Restoring from level {0}".format(level))
            backup = backups[level]
            read_pipe, write_pipe = multiprocessing.Pipe()
            process_stream = multiprocessing.Process(
                target=self.read_blocks,
                args=(backup, write_pipe, read_pipe, read_except_queue))

            process_stream.daemon = True
            process_stream.start()
            write_pipe.close()

            # Start the tar pipe consumer process

            # Use SimpleQueue because Queue does not work on Mac OS X.
            write_except_queue = queues.SimpleQueue()

            engine_stream = multiprocessing.Process(
                target=self.restore_level,
                args=(restore_resource, read_pipe, backup, write_except_queue))

            engine_stream.daemon = True
            engine_stream.start()

            read_pipe.close()
            write_pipe.close()
            process_stream.join()
            engine_stream.join()

            # SimpleQueue handling is different from queue handling.
            def handle_except_SimpleQueue(except_queue):
                if not except_queue.empty():
                    while not except_queue.empty():
                        e = except_queue.get()
                        LOG.exception('Engine error: {0}'.format(e))
                    return True
                else:
                    return False

            got_exception = None
            got_exception = (handle_except_SimpleQueue(read_except_queue) or
                             got_exception)
            got_exception = (handle_except_SimpleQueue(write_except_queue) or
                             got_exception)

            if engine_stream.exitcode or got_exception:
                raise engine_exceptions.EngineException(
                    "Engine error. Failed to restore.")

        LOG.info(
            'Restore completed successfully for backup name '
            '{0}'.format(hostname_backup_name))
Beispiel #4
0
    def restore(self, backup, restore_path, overwrite):
        """
        :type backup: freezer.storage.Backup
        """
        logging.info("Creation restore path: {0}".format(restore_path))
        utils.create_dir_tree(restore_path)
        if not overwrite and not utils.is_empty_dir(restore_path):
            raise Exception(
                "Restore dir is not empty. "
                "Please use --overwrite or provide different path.")
        logging.info("Creation restore path completed")
        for level in range(0, backup.level + 1):
            b = backup.full_backup.increments[level]
            logging.info("Restore backup {0}".format(b))

            # Use SimpleQueue because Queue does not work on Mac OS X.
            read_except_queue = SimpleQueue()

            read_pipe, write_pipe = multiprocessing.Pipe()
            process_stream = multiprocessing.Process(
                target=self.read_blocks,
                args=(b, write_pipe, read_pipe, read_except_queue))

            process_stream.daemon = True
            process_stream.start()
            write_pipe.close()

            # Start the tar pipe consumer process

            # Use SimpleQueue because Queue does not work on Mac OS X.
            write_except_queue = SimpleQueue()

            tar_stream = multiprocessing.Process(
                target=self.restore_level,
                args=(restore_path, read_pipe, backup, write_except_queue))

            tar_stream.daemon = True
            tar_stream.start()
            read_pipe.close()
            write_pipe.close()
            process_stream.join()
            tar_stream.join()

            # SimpleQueue handling is different from queue handling.
            def handle_except_SimpleQueue(except_queue):
                if not except_queue.empty():
                    while not except_queue.empty():
                        e = except_queue.get()
                        logging.critical('Engine error: {0}'.format(e))
                    return True
                else:
                    return False

            got_exception = None
            got_exception = (handle_except_SimpleQueue(read_except_queue) or
                             got_exception)
            got_exception = (handle_except_SimpleQueue(write_except_queue) or
                             got_exception)

            if tar_stream.exitcode or got_exception:
                raise EngineException("Engine error. Failed to restore.")

        logging.info(
            '[*] Restore execution successfully executed \
             for backup name {0}'.format(backup))
Beispiel #5
0
 def create_dirs(self, path):
     utils.create_dir_tree(path)