Generar backups de base de datos
This commit is contained in:
parent
6644eef0ab
commit
50a8c277bf
|
@ -1389,6 +1389,30 @@ def crear_db(nombre):
|
|||
return False
|
||||
|
||||
|
||||
def backup_dbs():
|
||||
con = sqlite3.connect(COMPANIES)
|
||||
cursor = con.cursor()
|
||||
sql = "SELECT * FROM names"
|
||||
cursor.execute(sql)
|
||||
rows = cursor.fetchall()
|
||||
if rows is None:
|
||||
return
|
||||
cursor.close()
|
||||
con.close()
|
||||
|
||||
for rfc, data in rows:
|
||||
args = loads(data)
|
||||
if args['type'] == 'postgres':
|
||||
path_bk = _join(PATH_MEDIA, 'tmp', '{}.bk'.format(rfc.lower()))
|
||||
args = 'pg_dump -U postgres -Fc {} > "{}"'.format(
|
||||
args['name'], path_bk)
|
||||
try:
|
||||
result = _call(args)
|
||||
except Exception as e:
|
||||
log.info(e)
|
||||
return
|
||||
|
||||
|
||||
class ImportFacturaLibre(object):
|
||||
|
||||
def __init__(self, path, rfc):
|
||||
|
|
|
@ -4190,9 +4190,10 @@ help_lr = 'Listar RFCs'
|
|||
@click.option('-t', '--test', is_flag=True, default=False)
|
||||
@click.option('-gap', '--generar-archivo-productos', is_flag=True, default=False)
|
||||
@click.option('-ip', '--importar-productos', is_flag=True, default=False)
|
||||
@click.option('-bk', '--backup-dbs', is_flag=True, default=False)
|
||||
def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc,
|
||||
borrar_rfc, listar_rfc, importar_valores, archivo, factura_libre, test,
|
||||
generar_archivo_productos, importar_productos):
|
||||
generar_archivo_productos, importar_productos, backup_dbs):
|
||||
|
||||
opt = locals()
|
||||
|
||||
|
@ -4284,6 +4285,9 @@ def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc,
|
|||
_importar_productos(opt['archivo'])
|
||||
sys.exit(0)
|
||||
|
||||
if opt['backup_dbs']:
|
||||
util.backup_dbs()
|
||||
|
||||
return
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue