def restore_database(self, input_path): """ Feed a mysqldump dumpfile to the mysql binary on stdin. :param input_path: :return: """ input_obj = resolve_input(input_path) dumpsize = input_obj.get_size() try: batch_processor = self.__runner.open_batch_processor() with input_obj.open() as dumpfile_data: with tqdm( desc="Restoring", total=dumpsize, unit="B", unit_scale=True, unit_divisor=1000, ) as bar: for chunk in self.__read_until_empty_byte(dumpfile_data): batch_processor.write(chunk) batch_processor.flush() bar.update(len(chunk)) finally: self.__runner.close_batch_processor()
def test_resolve_unknown(self): with pytest.raises(UnknownInputTypeError): resolve_input("unknown_file.bbs")
def test_resolve_gzip(self): for path in self.test_path_examples: test_path = path + "test.sql.gz" with self.subTest(i=test_path): assert isinstance(resolve_input(test_path), GzipInput)
def test_resolve_raw(self): for path in self.test_path_examples: test_path = path + "test.sql" with self.subTest(i=test_path): assert isinstance(resolve_input(test_path), RawInput)
def test_resolve_stdin(): assert isinstance(resolve_input("-"), StdInInput)