django-dbbackup icon indicating copy to clipboard operation
django-dbbackup copied to clipboard

Restore of database backup from S3 storage fails

Open MarkDoggen opened this issue 7 years ago • 6 comments

Restore of a compressed, encrypted database backup fails. Media restore (also compressed and encrypted) works fine though.

Media:

python manage.py mediarestore -z -e --passphrase pass
Restoring backup for media files
Finding latest backup
Restoring: media-2018-10-08-223640.tar.gz.gpg
Are you sure you want to continue? [Y/n] Y

Database:

python manage.py dbrestore -z -c --passphrase pass 
Finding latest backup
Restoring backup for database 'default' and server 'None'
Restoring: default-2018-10-08-221305.psql.gz.gpg
Restore tempfile created: 0 B
Are you sure you want to continue? [Y/n]

I thought it might be the size of the backup, so I started with truncated tables but it also shows the same behavior (Restore tempfile created: 0 B)

Does anyone have any clue what might be the issue here?

MarkDoggen avatar Oct 08 '18 21:10 MarkDoggen

@MarkDoggen What's your backup size from the storage ?

ZuluPro avatar Nov 21 '18 12:11 ZuluPro

It is 1.2 GB (compressed and encrypted)

MarkDoggen avatar Nov 21 '18 13:11 MarkDoggen

Hello, I had the same issue. Looking at the code, the only difference from applying both options together (decrypt and uncompress) is that the function uncompress_file receives a SpooledTemporaryFile instead of a normal file. Then the following line is responsible of uncompressing the file: zipfile = gzip.GzipFile(fileobj=inputfile, mode="rb") Probably GzipFile is not working with SpooledTemporaryFile. A possible solution is to first encrypt the file and then compress it. I check the size of the encrypt-compressed file after changing the order and is even smaller than compressing-encrypting.

bjassael avatar Nov 09 '19 22:11 bjassael

You can't compress an encrypted file. Compress first, then encrypt.

galt avatar Nov 15 '19 22:11 galt

@galt, I tested encrypting first and worked fine. Even, the encrypted-compress backup is smaller than the other way around. Captura de Pantalla 2019-11-15 a la(s) 20 19 57

Here a column that recommends encryption before compression for security: https://blog.appcanary.com/2016/encrypt-or-compress.html

@ZuluPro ZuluPro it's possible to commit this change?

bjassael avatar Nov 15 '19 23:11 bjassael

Your results seem miraculous. Please double-check them. Can you decompress and decrypt both of the files and recover the complete and correct original input? Perhaps you have labeled them backwards?

galt avatar Nov 20 '19 22:11 galt