Working on it ...

This commit is contained in:
Marcel Otte 2019-02-22 21:26:01 +01:00
parent 885a7682fb
commit fd52f70015
7 changed files with 192 additions and 6 deletions

5
backive/backive_service Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
"""
Service startup script.
"""

5
backive/backive_udev Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
"""
Callable script for udev rules.
"""

View File

@ -2,6 +2,7 @@ import os
import pwd import pwd
from ruamel.yaml import YAML from ruamel.yaml import YAML
import logging import logging
import jsonschema
from backive.core.backup import Backup from backive.core.backup import Backup
from backive.core.device import Device from backive.core.device import Device
@ -11,6 +12,11 @@ class Config:
def __init__(self): def __init__(self):
self._config = dict() self._config = dict()
self._schema = dict()
file_path = os.path.realpath(__file__)
schema_path = os.path.join(file_path, "schema.yml")
with open(schema_path, "r") as stream:
self._schema = YAML().load(stream)
def find_config(self): def find_config(self):
# who are we? # who are we?
@ -26,6 +32,7 @@ class Config:
with open(config_file, "r") as cfg: with open(config_file, "r") as cfg:
self._config = YAML().load(cfg) self._config = YAML().load(cfg)
jsonschema.validate(self._config, self._schema)
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
@ -55,7 +62,16 @@ class Config:
) )
return backups return backups
def get_globals(self): def get_device_backups(self, device):
if self._config.get("defaults", None): uuid = device
return self._config.get("defaults") device_name = self._config.get("devices").get(uuid).get("name")
backups = []
for backup in self.get_backups():
if backup.target == uuid or backup.target == device_name:
backups.append(backup)
return backups
def get_preferences(self):
if self._config.get("preferences", None):
return self._config.get("preferences")
return {} return {}

77
backive/config/schema.yml Normal file
View File

@ -0,0 +1,77 @@
### backive config schema
#
#
definitions:
device_section:
type: object
patternProperties:
"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$":
type: object
properties:
name:
type: string
mountname:
type: string
required:
- mountname
additionalProperties: false
backup_section:
type: object
patternProperties:
"^[a-zA-Z0-9_-]+$":
type: object
properties:
user:
type: string
from:
type: string
from_remote:
type: object
properties:
user:
type: string
password:
type: string
ssh_key_path:
type: string
to:
type: string
target_device:
type: string
frequency:
type: string
scripts:
type: array
items:
type: object
properties:
target:
enum: [ "local", "remote" ]
script:
type: string
additionalProperties: false
tool:
type: object
required:
- from
- to
- target_device
additionalProperties: false
preferences_section:
type: object
properties:
mount_root:
type: string
pattern: "^(/[^/]+)+$"
additionalProperties: false
type: object
properties:
devices:
"$ref": "#:/definitions/device_section"
backups:
"$ref": "#:/definitions/backup_section"
preferences:
"$ref": "#:/definitions/preferences_section"

59
doc/architecture.puml Normal file
View File

@ -0,0 +1,59 @@
@startuml "Overall architecture"
actor User
control udev
agent backive_udev
interface unix_socket
agent backive_service
file config
storage HDD_in_dockingstation
User --> HDD_in_dockingstation : 1. plugs in
udev <--> HDD_in_dockingstation : 2. recognizes hardware change
udev --> backive_udev : 3. calls with data of the HDD
backive_udev --> unix_socket : 4. delivers data to interface
backive_service <--> unix_socket : listens on and awaits data
backive_service <-- config
backive_service ==> HDD_in_dockingstation : 5. writes data like configured in config
@enduml
@startuml "Class architecture"
class backive_udev << (S,#FF0000) Script >>
class backive_service << (S,#FF0000) Script >>
class Service
note left
Runs known Backup instances based
on data provided by the EventInterface
end note
class EventInterface
class Config
class Backup
class Device
class Tool
backive_service --> Service : provides startup to
EventInterface --* Service
Config --* Service
Backup --* Service
Device --* Backup
Tool --* Backup
Config ..> Backup : generates Backup objects
backive_udev ..> EventInterface : sends data through unix socket
@enduml

View File

@ -0,0 +1,9 @@
[aliases]
test=pytest
[tool:pytest]
addopts = --verbose --cov=backive --pep8 --cov-report term-missing --pylint --pylint-error-types=E --pylint-jobs=4
python_files = tests/test_*.py
[build]
executable = /usr/bin/env python3

View File

@ -9,13 +9,28 @@ setup_info = dict(
version=VERSION, version=VERSION,
author="Marcel M. Otte", author="Marcel M. Otte",
author_email="qwc+backive@mmo.to", author_email="qwc+backive@mmo.to",
url="tbd", url="https://github.com/qwc/backive",
description="", description="Service for automatic backup of data to disks provided in hot-swap (SATA docking station)",
license="BSD", license="BSD",
classifiers=[ classifiers=[
], ],
scripts=[],
packages=find_packages(), packages=find_packages(),
setup_requires=[
"setuptools>=40.4.3",
"pytest>=3.8.2",
"pytest_runner>=4.2",
],
install_requires=[
"jsonschema==2.6.0"
],
tests_require=[
"pytest_cov>=2.6.0",
"pytest_pylint>=0.12.3",
"pytest-pep8>=1.0.6",
"pylint>=2.1.1",
"coverage>=4.5.1",
]
) )
setup(**setup_info) setup(**setup_info)