2015-07-08 16:02:14 +02:00
|
|
|
import logging
|
2024-11-28 23:20:19 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
from huey import RedisHuey
|
|
|
|
|
2015-07-08 16:02:14 +02:00
|
|
|
from tisbackup import tis_backup
|
|
|
|
|
2024-11-29 22:54:39 +01:00
|
|
|
huey = RedisHuey("tisbackup", host="localhost")
|
|
|
|
|
|
|
|
|
2015-07-08 16:02:14 +02:00
|
|
|
@huey.task()
|
|
|
|
def run_export_backup(base, config_file, mount_point, backup_sections):
|
|
|
|
try:
|
2024-11-29 22:54:39 +01:00
|
|
|
# Log
|
|
|
|
logger = logging.getLogger("tisbackup")
|
2015-07-08 16:02:14 +02:00
|
|
|
logger.setLevel(logging.INFO)
|
2024-11-29 22:54:39 +01:00
|
|
|
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
|
2015-07-08 16:02:14 +02:00
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
# Main
|
|
|
|
logger.info("Running export....")
|
|
|
|
|
|
|
|
if backup_sections:
|
|
|
|
backup_sections = backup_sections.split(",")
|
|
|
|
else:
|
|
|
|
backup_sections = []
|
2024-11-29 22:54:39 +01:00
|
|
|
backup = tis_backup(dry_run=False, verbose=True, backup_base_dir=base)
|
2015-07-08 16:02:14 +02:00
|
|
|
backup.read_ini_file(config_file)
|
|
|
|
mount_point = mount_point
|
2024-11-29 22:54:39 +01:00
|
|
|
backup.export_backups(backup_sections, mount_point)
|
2015-07-08 16:02:14 +02:00
|
|
|
except Exception as e:
|
2024-11-29 22:54:39 +01:00
|
|
|
return str(e)
|
2015-07-08 16:02:14 +02:00
|
|
|
|
|
|
|
finally:
|
|
|
|
os.system("/bin/umount %s" % mount_point)
|
|
|
|
os.rmdir(mount_point)
|
|
|
|
return "ok"
|
|
|
|
|
2024-11-29 22:54:39 +01:00
|
|
|
|
2015-07-08 16:02:14 +02:00
|
|
|
def get_task():
|
2024-11-29 22:54:39 +01:00
|
|
|
return task
|
|
|
|
|
2015-07-08 16:02:14 +02:00
|
|
|
|
|
|
|
def set_task(my_task):
|
2024-11-29 22:54:39 +01:00
|
|
|
global task
|
|
|
|
task = my_task
|
2015-07-08 16:02:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
task = None
|