From bffc0271870e6f9c573f3613502a36b627566ab3 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Wed, 10 May 2017 10:26:35 -0400 Subject: [PATCH] Deal properly with arcname and filter in tar backup --- umap/management/commands/backup.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/umap/management/commands/backup.py b/umap/management/commands/backup.py index bfc9b197..164c2c78 100644 --- a/umap/management/commands/backup.py +++ b/umap/management/commands/backup.py @@ -14,11 +14,16 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('path', help='Location of the backups.') - def archive(self, source, destination): + def archive(self, source, destination, arcname): + def exclude(tarinfo): + # Avoid archiving JSON layers gziped by nginx. + if tarinfo.name.endswith('.gz') or tarinfo.issym(): + return None + return tarinfo try: archive = tarfile.open(str(destination), mode='w:gz') - archive.add(str(source), arcname='./', recursive=True, - exclude=os.path.islink) + archive.add(str(source), arcname=arcname, recursive=True, + filter=exclude) except: # NOQA raise finally: @@ -33,7 +38,9 @@ class Command(BaseCommand): with database_tmp.open('w') as out: call_command('dumpdata', format='json', stdout=out) self.archive(database_tmp, - root.joinpath('database.{}.tar.gz'.format(today))) + root.joinpath('database.{}.tar.gz'.format(today)), + arcname='database.json') self.archive(settings.MEDIA_ROOT, - root.joinpath('media.{}.tar.gz'.format(today))) + root.joinpath('media.{}.tar.gz'.format(today)), + arcname='./') os.unlink(str(database_tmp))