Example #1
0
 def test_tar_bz2_file(self):
     """
     Check creation of tar.bz2.
     """
     filename = tempfile.mktemp(prefix='rdiffweb_test_archiver_', suffix='.tar.bz2')
     try:
         # Run archiver
         with open(filename, 'wb') as f:
             archive(self.path, f, encoding='utf-8', kind='tar.bz2')
         # Check result.
         self.assertInTar(TAR_EXPECTED, filename)
     finally:
         os.remove(filename)
Example #2
0
 def test_zip_file(self):
     """
     Check creation of a zipfile.
     """
     # Define path to be archived
     filename = tempfile.mktemp(prefix='rdiffweb_test_archiver_', suffix='.zip')
     try:
         # Run archiver
         with open(filename, 'wb') as f:
             archive(self.path, f, encoding='utf-8', kind='zip')
         # Check result.
         self.assertInZip(ZIP_EXPECTED, filename)
     finally:
         os.remove(filename)
Example #3
0
 def test_tar_file_cp1252(self):
     """
     Check if archiver support different encoding.
     """
     filename = tempfile.mktemp(prefix='rdiffweb_test_archiver_', suffix='.tar')
     try:
         # Run archiver
         with open(filename, 'wb') as f:
             archive(self.path, f, encoding='cp1252', kind='tar')
         # Check result.
         expected = {
             "Fichier avec non asci char Évelyne Mère.txt": 18,
         }
         self.assertInTar(expected, filename, equal=False)
     finally:
         os.remove(filename)
Example #4
0
        def _async(fdst):
            try:
                # Change thread name
                threading.currentThread(
                ).name = 'Restore' + threading.currentThread().name

                # Execute rdiff-backup to restore the data.
                logger.info("execute rdiff-backup --restore-as-of=%s %r %r",
                            restore_date, file_to_restore, output)
                try:
                    self.execute(
                        b"--restore-as-of=" +
                        str(restore_date).encode(encoding='latin1'),
                        file_to_restore, output)
                except ExecuteError:
                    raise UnknownError('unable to restore')
                logger.debug("restored locally completed")

                # Check the result
                if not os.access(output, os.F_OK):
                    error = '''rdiff-backup claimed success, but did not restore
                            anything. This indicates a bug in rdiffweb. Please
                            report this to a developer.'''
                    raise UnknownError(error)

                # Archive data or pipe data.
                if os.path.isdir(output):
                    archive(output,
                            fdst,
                            kind=kind,
                            encoding=self._encoding.name)
                else:
                    # Pipe the content of the file.
                    with io.open(output, 'rb') as fsrc:
                        copyfileobj(fsrc, fdst)
                logger.debug("restore completed")
            except:
                logger.error('restore failed', exc_info=1)
            finally:
                # Make sure to close pipe.
                fdst.close()
                # Clean up temp file or dir.
                if os.path.isdir(output):
                    shutil.rmtree(output, ignore_errors=True)
                elif os.path.exists(output):
                    os.remove(output)