def test_full_backup_01(self):
        """ Backup (with many fragmented files) -> Restore -> check result """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 200  # this ensures that each file will have multiple archives
        bck_params.disc_size = bck_params.single_archive_size

        self.do_backup_for_configuration(bck_params)
    def test_full_backup_00(self):
        """ Backup -> Restore -> check result """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 1050
        bck_params.disc_size = bck_params.single_archive_size

        self.do_backup_for_configuration(bck_params)
    def test_full_backup_02(self):
        """ Backup (with many fragmented files, encrypted) -> Restore -> check result """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 300  # this ensures that each file will have multiple archives
        bck_params.disc_size = bck_params.single_archive_size
        bck_params.encryption_key = "my awesome encryption key!&"

        self.do_backup_for_configuration(bck_params)
    def test_backup_02(self):
        """ Backup -> validate backup structure (encrypted) """
        bck_params = BackupParameters()
        bck_params.encryption_key = "encrypt me hard!"
        expected_extensions = ['tar.bz2.gpg', 'sqlite.gpg', 'yml']

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    # Every archive will be one(1) disc.
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    for subdir, dirs, files in os.walk(destination_dir):
                        for file in files:
                            ok = False
                            for ext in expected_extensions:
                                if file.endswith(ext):
                                    ok = True
                                    break

                            assert ok, "Found file that was not expected <%s>" % file
    def test_backup_00(self):
        """ Backup -> read database """
        bck_params = BackupParameters()

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    # Every archive will be one(1) disc.
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    db = DatabaseManager(db_filename.name)
                    backup_reader = db.read_backup(None)

                    for file in src_file_list:
                        relative_file = file[len(bck_params.database_location
                                                 ):]
                        test = backup_reader.find_relative_file(relative_file)
                        assert test is not None
示例#6
0
 def __init__(self, parameters: BackupParameters,
              general_settings: GeneralSettings):
     super(BackupDirectoryStorageController, self).__init__()
     self._current_medium_size = 0
     self._parameters = parameters
     parameters.backup_parameters = parameters.backup_parameters or DirectoryStorageBackupParameters(
     )  # TODO remove
     print(" Medium size : ", parameters.backup_parameters.medium_size)
     self._general_settings = general_settings
     self._hook_helper = HookHelper(general_settings)
     self.disc_directories = list()
     self.disc_directory = None
    def test_full_backup_04(self):
        """ Backup -> change one file -> Backup -> check if 2nd backup """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 1050
        bck_params.disc_size = bck_params.single_archive_size

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_root:
                destination_dir1 = destination_root + "/0"
                os.mkdir(destination_dir1)
                destination_dir2 = destination_root + "/1"
                os.mkdir(destination_dir2)

                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir1

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    # change the source
                    self.create_test_file(src_file_list[0], -1)

                    bck_params = BackupParameters()
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size
                    bck_params.destination = destination_dir2

                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    for subdir, dirs, files in os.walk(destination_dir2):
                        assert len(dirs) != 0 or len(files) != 0, \
                            "There should be directories <%s> or files <%s>" % (dirs, files)

                    with tempfile.TemporaryDirectory() as restore_dir:
                        rst_params = RestoreParameters()
                        rst_params.database_location = db_filename.name
                        rst_params.source = destination_root
                        rst_params.destination = restore_dir
                        rst_params.encryption_key = bck_params.encryption_key

                        ctrl = RestoreController(GeneralSettings())
                        ctrl.execute(rst_params)

                        assert DirCompare(source_dir, restore_dir).compare()
    def test_full_backup_03(self):
        """ Backup -> Backup -> check if 2nd backup is empty """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 1050
        bck_params.disc_size = bck_params.single_archive_size

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    with tempfile.TemporaryDirectory() as destination_dir2:
                        bck_params = BackupParameters()
                        bck_params.database_location = db_filename.name
                        bck_params.source = source_dir
                        bck_params.single_archive_size = 1050
                        bck_params.disc_size = bck_params.single_archive_size
                        bck_params.destination = destination_dir2

                        ctrl = BackupController(GeneralSettings())

                        # Preparations complete start backup...
                        ctrl.execute(bck_params)
                        # ... backup ended.

                        for subdir, dirs, files in os.walk(destination_dir2):
                            assert len(
                                dirs
                            ) == 0, "Found file that was not expected <%s>" % dirs