mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 13:41:49 +02:00
Deal properly with arcname and filter in tar backup
This commit is contained in:
parent
7d62453408
commit
899228e954
1 changed files with 12 additions and 5 deletions
|
@ -14,11 +14,16 @@ class Command(BaseCommand):
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('path', help='Location of the backups.')
|
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:
|
try:
|
||||||
archive = tarfile.open(str(destination), mode='w:gz')
|
archive = tarfile.open(str(destination), mode='w:gz')
|
||||||
archive.add(str(source), arcname='./', recursive=True,
|
archive.add(str(source), arcname=arcname, recursive=True,
|
||||||
exclude=os.path.islink)
|
filter=exclude)
|
||||||
except: # NOQA
|
except: # NOQA
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
@ -33,7 +38,9 @@ class Command(BaseCommand):
|
||||||
with database_tmp.open('w') as out:
|
with database_tmp.open('w') as out:
|
||||||
call_command('dumpdata', format='json', stdout=out)
|
call_command('dumpdata', format='json', stdout=out)
|
||||||
self.archive(database_tmp,
|
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,
|
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))
|
os.unlink(str(database_tmp))
|
||||||
|
|
Loading…
Reference in a new issue