Backups in thread
This commit is contained in:
parent
f99a0da8d9
commit
f2c9de3660
|
@ -1389,6 +1389,42 @@ def crear_db(nombre):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _to_seafile(path_db, data):
|
||||||
|
msg = '\tSincronizando backup...'
|
||||||
|
log.info(msg)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _backup_and_sync(rfc, data):
|
||||||
|
msg = 'Generando backup de: {}'.format(rfc)
|
||||||
|
log.info(msg)
|
||||||
|
|
||||||
|
sql = 'select correo_timbrado, token_timbrado from emisor;'
|
||||||
|
path_bk = _join(PATH_MEDIA, 'tmp', '{}.bk'.format(rfc.lower()))
|
||||||
|
if data['type'] == 'postgres':
|
||||||
|
args = 'pg_dump -U postgres -Fc {} > "{}"'.format(
|
||||||
|
data['name'], path_bk)
|
||||||
|
sql = 'psql -U postgres -d {} -Atc "{}"'.format(data['name'], sql)
|
||||||
|
elif data['type'] == 'sqlite':
|
||||||
|
args = 'gzip -c "{}" > "{}"'.format(data['name'], path_bk)
|
||||||
|
sql = 'sqlite3 "{}" "{}"'.format(data['name'], sql)
|
||||||
|
try:
|
||||||
|
result = _call(args)
|
||||||
|
msg = '\tBackup generado...'
|
||||||
|
log.info(msg)
|
||||||
|
result = _call(sql).strip().split('|')
|
||||||
|
if len(result) < 2:
|
||||||
|
return
|
||||||
|
if not result[0] or not result[1]:
|
||||||
|
return
|
||||||
|
|
||||||
|
_to_seafile(path_bk, result)
|
||||||
|
except Exception as e:
|
||||||
|
log.info(e)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def backup_dbs():
|
def backup_dbs():
|
||||||
con = sqlite3.connect(COMPANIES)
|
con = sqlite3.connect(COMPANIES)
|
||||||
cursor = con.cursor()
|
cursor = con.cursor()
|
||||||
|
@ -1402,16 +1438,8 @@ def backup_dbs():
|
||||||
|
|
||||||
for rfc, data in rows:
|
for rfc, data in rows:
|
||||||
args = loads(data)
|
args = loads(data)
|
||||||
path_bk = _join(PATH_MEDIA, 'tmp', '{}.bk'.format(rfc.lower()))
|
run_in_thread(_backup_and_sync(rfc, args))
|
||||||
if args['type'] == 'postgres':
|
|
||||||
args = 'pg_dump -U postgres -Fc {} > "{}"'.format(
|
|
||||||
args['name'], path_bk)
|
|
||||||
elif args['type'] == 'sqlite':
|
|
||||||
args = 'gzip -c "{}" > "{}"'.format(args['name'], path_bk)
|
|
||||||
try:
|
|
||||||
result = _call(args)
|
|
||||||
except Exception as e:
|
|
||||||
log.info(e)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue