Skip to content

Commit

Permalink
Fix restore on S3 storage databases (#503)
Browse files Browse the repository at this point in the history
Co-authored-by: Archmonger <16909269+Archmonger@users.noreply.github.com>
  • Loading branch information
truePhilipp and Archmonger authored Jan 29, 2024
1 parent b67a437 commit a8deb81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions dbbackup/tests/functional/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions dbbackup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down

0 comments on commit a8deb81

Please sign in to comment.