This commit is contained in:
Einar Forselv 2019-12-05 11:09:36 +01:00
parent 0a9e5edfe4
commit 6f06d25db5
7 changed files with 12 additions and 12 deletions

View File

@ -2,7 +2,6 @@ import logging
from restic_compose_backup.alerts.smtp import SMTPAlert from restic_compose_backup.alerts.smtp import SMTPAlert
from restic_compose_backup.alerts.discord import DiscordWebhookAlert from restic_compose_backup.alerts.discord import DiscordWebhookAlert
from restic_compose_backup.config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -37,7 +36,7 @@ def configured_alert_types():
for cls in BACKENDS: for cls in BACKENDS:
instance = cls.create_from_env() instance = cls.create_from_env()
logger.debug("Alert backend '%s' configured: %s", cls.name, instance != None) logger.debug("Alert backend '%s' configured: %s", cls.name, instance is not None)
if instance: if instance:
entires.append(instance) entires.append(instance)

View File

@ -1,6 +1,5 @@
import os import os
import logging import logging
from urllib.parse import urlparse
import requests import requests
from restic_compose_backup.alerts.base import BaseAlert from restic_compose_backup.alerts.base import BaseAlert
@ -41,6 +40,6 @@ class DiscordWebhookAlert(BaseAlert):
} }
response = requests.post(self.url, params={'wait': True}, json=data) response = requests.post(self.url, params={'wait': True}, json=data)
if response.status_code not in self.success_codes: if response.status_code not in self.success_codes:
log.error("Discord webhook failed: %s: %s", response.status_code, response.content) logger.error("Discord webhook failed: %s: %s", response.status_code, response.content)
else: else:
logger.info('Discord webhook successful') logger.info('Discord webhook successful')

View File

@ -1,5 +1,4 @@
import argparse import argparse
import pprint
import logging import logging
from restic_compose_backup import ( from restic_compose_backup import (
@ -63,7 +62,8 @@ def status(config, containers):
ping = instance.ping() ping = instance.ping()
logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0)
if ping != 0: if ping != 0:
logger.error("Database '%s' in service %s cannot be reached", instance.container_type, container.service_name) logger.error("Database '%s' in service %s cannot be reached",
instance.container_type, container.service_name)
if len(backup_containers) == 0: if len(backup_containers) == 0:
logger.info("No containers in the project has 'restic-compose-backup.enabled' label") logger.info("No containers in the project has 'restic-compose-backup.enabled' label")
@ -185,6 +185,7 @@ def cleanup(config, containers):
prune_result = restic.prune(config.repository) prune_result = restic.prune(config.repository)
return forget_result == 0 and prune_result == 0 return forget_result == 0 and prune_result == 0
def snapshots(config, containers): def snapshots(config, containers):
"""Display restic snapshots""" """Display restic snapshots"""
stdout, stderr = restic.snapshots(config.repository, last=True) stdout, stderr = restic.snapshots(config.repository, last=True)

View File

@ -6,7 +6,7 @@ logger = logging.getLogger(__name__)
def test(): def test():
return run_command(['ls', '/volumes']) return run(['ls', '/volumes'])
def ping_mysql(host, port, username) -> int: def ping_mysql(host, port, username) -> int:
@ -23,7 +23,7 @@ def ping_mysql(host, port, username) -> int:
]) ])
def ping_mariadb(host, port, username): #, password) -> int: def ping_mariadb(host, port, username) -> int:
"""Check if the mariadb is up and can be reached""" """Check if the mariadb is up and can be reached"""
return run([ return run([
'mysqladmin', 'mysqladmin',
@ -43,7 +43,7 @@ def ping_postgres(host, port, username, password) -> int:
"pg_isready", "pg_isready",
f"--host={host}", f"--host={host}",
f"--port={port}", f"--port={port}",
f"--username={username}", f"--username={username}",
]) ])

View File

@ -68,7 +68,7 @@ class Container:
def get_config_env(self, name) -> str: def get_config_env(self, name) -> str:
"""Get a config environment variable by name""" """Get a config environment variable by name"""
# convert to dict and fetch env var by name # convert to dict and fetch env var by name
data = {i[0:i.find('=')]: i[i.find('=')+1:] for i in self.environment} data = {i[0:i.find('=')]: i[i.find('=') + 1:] for i in self.environment}
return data.get(name) return data.get(name)
def set_config_env(self, name, value): def set_config_env(self, name, value):
@ -169,7 +169,7 @@ class Container:
return self._labels.get(name, None) return self._labels.get(name, None)
def filter_mounts(self): def filter_mounts(self):
"""Get all mounts for this container matching include/exclude filters""" """Get all mounts for this container matching include/exclude filters"""
filtered = [] filtered = []
if not self.volume_backup_enabled: if not self.volume_backup_enabled:

View File

@ -13,6 +13,7 @@ LOG_LEVELS = {
'error': logging.ERROR, 'error': logging.ERROR,
} }
def setup(level: str = 'warning'): def setup(level: str = 'warning'):
"""Set up logging""" """Set up logging"""
level = level or "" level = level or ""

View File

@ -63,7 +63,7 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str])
def snapshots(repository: str, last=True) -> Tuple[str, str]: def snapshots(repository: str, last=True) -> Tuple[str, str]:
args = ["snapshots"] args = ["snapshots"]
if last: if last:
args.append('--last') args.append('--last')
return commands.run_capture_std(restic(repository, args)) return commands.run_capture_std(restic(repository, args))