Three lint errors remain.
continuous-integration/drone the build failed Details

pull/15/head
Jef Roosens 2021-04-26 18:00:56 +02:00
parent 83ea06f016
commit 8a7f47dfcd
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
4 changed files with 26 additions and 8 deletions

View File

@ -23,8 +23,7 @@ class ContainerSpec(Spec):
mountpoint: str, mountpoint: str,
notify=None, notify=None,
): ):
""" """Create a new ContainerSpec object.
Create a new ContainerSpec object.
Args: Args:
name: name of the spec (used as an identifier) name: name of the spec (used as an identifier)
@ -36,7 +35,7 @@ class ContainerSpec(Spec):
perform a specified backup and output this data to stdout. This perform a specified backup and output this data to stdout. This
output then gets piped to a backup file. output then gets piped to a backup file.
extension: the extension of the backup files. extension: the extension of the backup files.
mountpoint: mountpoint: I don't actually know, this never gets used
notify: notifier object (may be None) notify: notifier object (may be None)
""" """
super().__init__(name, destination, limit, extension, notify) super().__init__(name, destination, limit, extension, notify)

View File

@ -26,8 +26,7 @@ class DirectorySpec(Spec):
extension: str, extension: str,
notify=None, notify=None,
): ):
""" """Initialize a new DirectorySpec object.
Initialize a new DirectorySpec object.
Args: Args:
name: name of the spec name: name of the spec

View File

@ -41,7 +41,8 @@ class Spec:
name: name of the spec name: name of the spec
destination: directory where the backups shall reside destination: directory where the backups shall reside
limit: max amount of backups limit: max amount of backups
notifier: notifier object extension: file extension of the backup files
notify: notifier object to send IFTT notifications
""" """
self.name = name self.name = name
self.destination = Path(destination) self.destination = Path(destination)
@ -119,5 +120,6 @@ class Spec:
def to_dict(self): def to_dict(self):
"""Export the class as a dictionary. """Export the class as a dictionary.
This function should be imnplemented by the subclasses.""" This function should be imnplemented by the subclasses.
"""
raise NotImplementedError() raise NotImplementedError()

View File

@ -1,3 +1,6 @@
"""Module defining a Docker volume-based spec."""
from .spec import Spec from .spec import Spec
from typing import Union from typing import Union
from pathlib import Path from pathlib import Path
@ -25,6 +28,18 @@ class VolumeSpec(Spec):
extension: str, extension: str,
notify=None, notify=None,
): ):
"""Initialize a new VolumeSpec object.
Args:
name: name of the spec
volume: Docker volume to back up
image: base image to use to run backup command
destination: where to store the backup files
limit: max backup files to keep
command: backup command to run within the base image
extension: file extension of the backup files
notify: Notifier object
"""
super().__init__(name, destination, limit, extension, notify) super().__init__(name, destination, limit, extension, notify)
self.volume = volume self.volume = volume
@ -32,6 +47,7 @@ class VolumeSpec(Spec):
self.command = command self.command = command
def backup(self): def backup(self):
"""Create a new backup."""
# Remove excess backups # Remove excess backups
self.remove_backups() self.remove_backups()
@ -40,8 +56,10 @@ class VolumeSpec(Spec):
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), self.extension datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), self.extension
) )
base_cmd = "docker run --rm -v '{}:/from' -v '{}:/to' -w /from '{}' {}"
process = subprocess.run( process = subprocess.run(
"docker run --rm -v '{}:/from' -v '{}:/to' -w /from '{}' {}".format( base_cmd.format(
self.volume, self.volume,
self.destination, self.destination,
self.image, self.image,