2019-01-06 17:34:02 +01:00
|
|
|
import os
|
2020-01-06 23:01:25 +01:00
|
|
|
import logging
|
2020-03-18 21:09:17 +01:00
|
|
|
from subprocess import Popen
|
|
|
|
import asyncio
|
2019-01-06 17:34:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Backup:
|
2019-01-06 21:29:21 +01:00
|
|
|
def __init__(self, name, cfg=None):
|
2019-02-24 22:42:36 +01:00
|
|
|
self.name = name
|
|
|
|
self.config = cfg
|
2019-01-06 17:34:02 +01:00
|
|
|
|
2020-01-05 13:17:46 +01:00
|
|
|
@classmethod
|
|
|
|
def instance(cls, name, config=None):
|
2020-01-06 23:01:25 +01:00
|
|
|
logging.debug("Backup instance created (%s)", name)
|
2020-01-05 13:17:46 +01:00
|
|
|
return Backup(name, config)
|
|
|
|
|
2019-05-03 21:36:44 +02:00
|
|
|
def get_frequency(self):
|
|
|
|
return self.config.get("frequency", None)
|
|
|
|
|
2020-03-18 21:09:17 +01:00
|
|
|
async def run(self):
|
|
|
|
logging.debug("Running backup %s", self.name)
|
|
|
|
if self.config.get("scripts", None) is not None:
|
|
|
|
logging.debug("Executing script..")
|
|
|
|
proc = await asyncio.create_subprocess_shell(
|
|
|
|
self.config.get("script"),
|
|
|
|
stdout=asyncio.subprocess.PIPE,
|
|
|
|
stderr=asyncio.subprocess.PIPE
|
|
|
|
)
|
|
|
|
stdout, stderr = await proc.communicate()
|
|
|
|
logging.debug("stdout: %s", stdout)
|
|
|
|
return stdout
|