TISbackup/tasks.py

52 lines
1.2 KiB
Python
Raw Permalink Normal View History

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
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:
# Log
logger = logging.getLogger("tisbackup")
2015-07-08 16:02:14 +02:00
logger.setLevel(logging.INFO)
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 = []
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
backup.export_backups(backup_sections, mount_point)
2015-07-08 16:02:14 +02:00
except Exception as e:
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"
2015-07-08 16:02:14 +02:00
def get_task():
return task
2015-07-08 16:02:14 +02:00
def set_task(my_task):
global task
task = my_task
2015-07-08 16:02:14 +02:00
task = None