From a8deb81eca8823d0aeb9cdb511d5b2162f06ea87 Mon Sep 17 00:00:00 2001 From: Philipp <49057914+truePhilipp@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:44:23 +0100 Subject: [PATCH] Fix restore on S3 storage databases (#503) Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com> --- dbbackup/tests/functional/test_commands.py | 12 ++++++++++++ dbbackup/utils.py | 1 + docs/changelog.rst | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dbbackup/tests/functional/test_commands.py b/dbbackup/tests/functional/test_commands.py index dd250649..8434a5ca 100644 --- a/dbbackup/tests/functional/test_commands.py +++ b/dbbackup/tests/functional/test_commands.py @@ -102,6 +102,8 @@ def test_compressed(self, *args): self.instance.delete() # Restore execute_from_command_line(["", "dbrestore", "--uncompress"]) + restored = models.CharModel.objects.all().exists() + self.assertTrue(restored) def test_no_backup_available(self, *args): with self.assertRaises(SystemExit): @@ -131,6 +133,16 @@ def test_specify_db(self, *args): # Restore execute_from_command_line(["", "dbrestore", "--database", "default"]) + @patch("dbbackup.utils.getpass", return_value=None) + def test_compressed_and_encrypted(self, *args): + # Create backup + execute_from_command_line(["", "dbbackup", "--compress", "--encrypt"]) + self.instance.delete() + # Restore + execute_from_command_line(["", "dbrestore", "--uncompress", "--decrypt"]) + restored = models.CharModel.objects.all().exists() + self.assertTrue(restored) + class MediaBackupCommandTest(TestCase): def setUp(self): diff --git a/dbbackup/utils.py b/dbbackup/utils.py index ed4b4520..408b4356 100644 --- a/dbbackup/utils.py +++ b/dbbackup/utils.py @@ -278,6 +278,7 @@ def uncompress_file(inputfile, filename): """ zipfile = gzip.GzipFile(fileobj=inputfile, mode="rb") try: + inputfile.seek(0) outputfile = create_spooled_temporary_file(fileobj=zipfile) finally: zipfile.close() diff --git a/docs/changelog.rst b/docs/changelog.rst index f12e3d90..176b7573 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,7 +4,7 @@ Changelog Unreleased ---------- -* Nothing (yet)! +* Fix restore of database from S3 storage by reintroducing inputfile.seek(0) to utils.uncompress_file 4.1.0 (2024-01-14) ------------------