From 2896a53c761868b7da5684016d058c18f26b9763 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Fri, 20 Apr 2018 18:21:57 -0300 Subject: [PATCH] Gera pacote de migracao no repo --- sapl/legacy/migracao.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sapl/legacy/migracao.py b/sapl/legacy/migracao.py index 3840b1106..4446324c4 100644 --- a/sapl/legacy/migracao.py +++ b/sapl/legacy/migracao.py @@ -1,12 +1,10 @@ import subprocess -import tarfile - -from django.conf import settings from sapl.legacy.migracao_dados import REPO, gravar_marco, migrar_dados from sapl.legacy.migracao_documentos import migrar_documentos from sapl.legacy.migracao_usuarios import migrar_usuarios from sapl.legacy.scripts.exporta_zope.variaveis_comuns import TAG_ZOPE +from sapl.legacy_migration_settings import DIR_REPO, NOME_BANCO_LEGADO def adornar_msg(msg): @@ -21,25 +19,23 @@ def migrar(interativo=False): migrar_usuarios(REPO.working_dir) migrar_documentos(REPO) gravar_marco() + gerar_pacote() def gerar_pacote(): - banco = settings.DATABASES['legacy']['NAME'] # backup do banco print('Gerando backup do banco... ', end='', flush=True) - arq_backup = settings.MEDIA_ROOT.child('{}.backup'.format(banco)) + arq_backup = DIR_REPO.child('{}.backup'.format(NOME_BANCO_LEGADO)) backup_cmd = ''' pg_dump --host localhost --port 5432 --username postgres --no-password --format custom --blobs --verbose --file {} {}'''.format( - arq_backup, banco) + arq_backup, NOME_BANCO_LEGADO) subprocess.check_output(backup_cmd.split(), stderr=subprocess.DEVNULL) print('SUCESSO') # tar de media/sapl print('Criando tar de media... ', end='', flush=True) - tar_media = settings.MEDIA_ROOT.child('{}.media.tgz'.format(banco)) - dir_media = settings.MEDIA_ROOT.child('sapl') - with tarfile.open(tar_media, "w:gz") as tar: - tar.add(dir_media, arcname=dir_media.name) + arq_tar = DIR_REPO.child('{}.media.tar'.format(NOME_BANCO_LEGADO)) + subprocess.check_output(['tar', 'cfh', arq_tar, '-C', DIR_REPO, 'sapl']) print('SUCESSO')