From fc5c6cc91428db8c3746171e287619b25f438595 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Tue, 3 Dec 2019 09:40:02 +0100 Subject: [PATCH] Rename project --- Dockerfile | 4 ++-- README.md | 10 +++++----- crontab | 2 +- docker-compose.yaml | 14 ++++++------- ...me_backup.env => restic_compose_backup.env | 0 .../backup_runner.py | 2 +- .../cli.py | 20 ++++++++++--------- .../commands.py | 0 .../config.py | 0 .../containers.py | 18 ++++++++--------- .../containers_db.py | 8 ++++---- .../log.py | 2 +- .../mail.py | 2 +- .../restic.py | 2 +- .../utils.py | 2 +- setup.py | 12 +++++------ tests/fixtures.py | 2 +- tests/tests.py | 16 +++++++-------- 18 files changed, 59 insertions(+), 57 deletions(-) rename restic_volume_backup.env => restic_compose_backup.env (100%) rename {restic_volume_backup => restic_compose_backup}/backup_runner.py (97%) rename {restic_volume_backup => restic_compose_backup}/cli.py (88%) rename {restic_volume_backup => restic_compose_backup}/commands.py (100%) rename {restic_volume_backup => restic_compose_backup}/config.py (100%) rename {restic_volume_backup => restic_compose_backup}/containers.py (94%) rename {restic_volume_backup => restic_compose_backup}/containers_db.py (95%) rename {restic_volume_backup => restic_compose_backup}/log.py (85%) rename {restic_volume_backup => restic_compose_backup}/mail.py (93%) rename {restic_volume_backup => restic_compose_backup}/restic.py (97%) rename {restic_volume_backup => restic_compose_backup}/utils.py (95%) diff --git a/Dockerfile b/Dockerfile index 50d0409..91acbcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM restic/restic:0.9.6 RUN apk update && apk add python3 dcron mariadb-client postgresql-client -ADD . /restic-volume-backup -WORKDIR /restic-volume-backup +ADD . /restic-compose-backup +WORKDIR /restic-compose-backup RUN pip3 install -U pip setuptools RUN pip3 install -e . diff --git a/README.md b/README.md index 0c19f77..3288776 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# restic-volume-backup +# restic-compose-backup *WORK IN PROGRESS* @@ -67,8 +67,8 @@ A simple `include` and `exclude` filter is also available. example: image: some_image labels: - restic-volume-backup.enabled: true - restic-volume-backup.include: "files,data" + restic-volume-backup.volumes: true + restic-volume-backup.volumes.include: "files,data" volumes: # Source don't match include filter. No backup. - media:/srv/media @@ -88,8 +88,8 @@ Exclude example: image: some_image labels: - restic-volume-backup.enabled: true - restic-volume-backup.exclude: "media" + restic-volume-backup.volumes: true + restic-volume-backup.volumes.exclude: "media" volumes: # Excluded by filter - media:/srv/media diff --git a/crontab b/crontab index e45d143..ea3aebd 100644 --- a/crontab +++ b/crontab @@ -1 +1 @@ -1 * * * * source /env.sh && rvb backup > /proc/1/fd/1 +1 * * * * source /env.sh && rcb backup > /proc/1/fd/1 diff --git a/docker-compose.yaml b/docker-compose.yaml index de33e9e..a818764 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,7 +3,7 @@ services: backup: build: . env_file: - - restic_volume_backup.env + - restic_compose_backup.env volumes: # Map in docker socket - /var/run/docker.sock:/tmp/docker.sock:ro @@ -11,12 +11,12 @@ services: - ./restic_data:/restic_data - ./restic_cache:/restic_cache # Map in project source - - .:/restic-volume-backup + - .:/restic-compose-backup web: image: nginx labels: - restic-volume-backup.volumes: true - restic-volume-backup.include: "/tests" + restic-compose-backup.volumes: true + restic-compose-backup.volumes.include: "/tests" volumes: - ./tests:/srv/tests - ./.vscode:/srv/code @@ -27,7 +27,7 @@ services: mysql: image: mysql:5 labels: - restic-volume-backup.mysql: true + restic-compose-backup.mysql: true environment: - MYSQL_ROOT_PASSWORD=my-secret-pw - MYSQL_DATABASE=mydb @@ -39,7 +39,7 @@ services: mariadb: image: mariadb:10 labels: - restic-volume-backup.mariadb: true + restic-compose-backup.mariadb: true environment: - MYSQL_ROOT_PASSWORD=my-secret-pw - MYSQL_DATABASE=mydb @@ -51,7 +51,7 @@ services: postgres: image: postgres:11 labels: - restic-volume-backup.postgres: true + restic-compose-backup.postgres: true environment: - POSTGRES_USER=pguser - POSTGRES_PASSWORD=pgpassword diff --git a/restic_volume_backup.env b/restic_compose_backup.env similarity index 100% rename from restic_volume_backup.env rename to restic_compose_backup.env diff --git a/restic_volume_backup/backup_runner.py b/restic_compose_backup/backup_runner.py similarity index 97% rename from restic_volume_backup/backup_runner.py rename to restic_compose_backup/backup_runner.py index 5f374e4..14feb85 100644 --- a/restic_volume_backup/backup_runner.py +++ b/restic_compose_backup/backup_runner.py @@ -2,7 +2,7 @@ import logging import os import docker -from restic_volume_backup.config import Config +from restic_compose_backup.config import Config logger = logging.getLogger(__name__) diff --git a/restic_volume_backup/cli.py b/restic_compose_backup/cli.py similarity index 88% rename from restic_volume_backup/cli.py rename to restic_compose_backup/cli.py index 228e5f5..64573b4 100644 --- a/restic_volume_backup/cli.py +++ b/restic_compose_backup/cli.py @@ -2,11 +2,13 @@ import argparse import pprint import logging -from restic_volume_backup import log -from restic_volume_backup.config import Config -from restic_volume_backup.containers import RunningContainers -from restic_volume_backup import backup_runner -from restic_volume_backup import restic +from restic_compose_backup import ( + backup_runner, + log, + restic, +) +from restic_compose_backup.config import Config +from restic_compose_backup.containers import RunningContainers logger = logging.getLogger(__name__) @@ -50,7 +52,7 @@ def status(config, containers): logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) if len(backup_containers) == 0: - logger.info("No containers in the project has 'restic-volume-backup.enabled' label") + logger.info("No containers in the project has 'restic-compose-backup.enabled' label") def backup(config, containers): @@ -75,12 +77,12 @@ def backup(config, containers): result = backup_runner.run( image=containers.this_container.image, - command='restic-volume-backup start-backup-process', + command='restic-compose-backup start-backup-process', volumes=volumes, environment=containers.this_container.environment, source_container_id=containers.this_container.id, labels={ - "restic-volume-backup.backup_process": 'True', + "restic-compose-backup.backup_process": 'True', "com.docker.compose.project": containers.this_container.project_name, }, ) @@ -125,7 +127,7 @@ def start_backup_process(config, containers): def parse_args(): - parser = argparse.ArgumentParser(prog='restic_volume_backup') + parser = argparse.ArgumentParser(prog='restic_compose_backup') parser.add_argument( 'action', choices=['status', 'backup', 'start-backup-process'], diff --git a/restic_volume_backup/commands.py b/restic_compose_backup/commands.py similarity index 100% rename from restic_volume_backup/commands.py rename to restic_compose_backup/commands.py diff --git a/restic_volume_backup/config.py b/restic_compose_backup/config.py similarity index 100% rename from restic_volume_backup/config.py rename to restic_compose_backup/config.py diff --git a/restic_volume_backup/containers.py b/restic_compose_backup/containers.py similarity index 94% rename from restic_volume_backup/containers.py rename to restic_compose_backup/containers.py index e8560e1..78032f8 100644 --- a/restic_volume_backup/containers.py +++ b/restic_compose_backup/containers.py @@ -2,7 +2,7 @@ import os from pathlib import Path from typing import List -from restic_volume_backup import utils +from restic_compose_backup import utils VOLUME_TYPE_BIND = "bind" VOLUME_TYPE_VOLUME = "volume" @@ -27,15 +27,15 @@ class Container: if self._labels is None: raise ValueError('Container meta missing Config->Labels') - self._include = self._parse_pattern(self.get_label('restic-volume-backup.include')) - self._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude')) + self._include = self._parse_pattern(self.get_label('restic-compose-backup.volumes.include')) + self._exclude = self._parse_pattern(self.get_label('restic-compose-backup.volumes.exclude')) @property def instance(self) -> 'Container': """Container: Get a service specific subclass instance""" # TODO: Do this smarter in the future (simple registry) if self.database_backup_enabled: - from restic_volume_backup import containers_db + from restic_compose_backup import containers_db if self.mariadb_backup_enabled: return containers_db.MariadbContainer(self._data) if self.mysql_backup_enabled: @@ -96,7 +96,7 @@ class Container: @property def volume_backup_enabled(self) -> bool: - return utils.is_true(self.get_label('restic-volume-backup.volumes')) + return utils.is_true(self.get_label('restic-compose-backup.volumes')) @property def database_backup_enabled(self) -> bool: @@ -109,20 +109,20 @@ class Container: @property def mysql_backup_enabled(self) -> bool: - return utils.is_true(self.get_label('restic-volume-backup.mysql')) + return utils.is_true(self.get_label('restic-compose-backup.mysql')) @property def mariadb_backup_enabled(self) -> bool: - return utils.is_true(self.get_label('restic-volume-backup.mariadb')) + return utils.is_true(self.get_label('restic-compose-backup.mariadb')) @property def postgresql_backup_enabled(self) -> bool: - return utils.is_true(self.get_label('restic-volume-backup.postgres')) + return utils.is_true(self.get_label('restic-compose-backup.postgres')) @property def is_backup_process_container(self) -> bool: """Is this container the running backup process?""" - return self.get_label('restic-volume-backup.backup_process') == 'True' + return self.get_label('restic-compose-backup.backup_process') == 'True' @property def is_running(self) -> bool: diff --git a/restic_volume_backup/containers_db.py b/restic_compose_backup/containers_db.py similarity index 95% rename from restic_volume_backup/containers_db.py rename to restic_compose_backup/containers_db.py index 9b03c19..abc4904 100644 --- a/restic_volume_backup/containers_db.py +++ b/restic_compose_backup/containers_db.py @@ -1,10 +1,10 @@ -from restic_volume_backup.containers import Container -from restic_volume_backup.config import Config -from restic_volume_backup import ( +from restic_compose_backup.containers import Container +from restic_compose_backup.config import Config +from restic_compose_backup import ( commands, restic, ) -from restic_volume_backup import utils +from restic_compose_backup import utils class MariadbContainer(Container): diff --git a/restic_volume_backup/log.py b/restic_compose_backup/log.py similarity index 85% rename from restic_volume_backup/log.py rename to restic_compose_backup/log.py index 20a0684..4dbc59b 100644 --- a/restic_volume_backup/log.py +++ b/restic_compose_backup/log.py @@ -2,7 +2,7 @@ import logging import os import sys -logger = logging.getLogger('restic_volume_backup') +logger = logging.getLogger('restic_compose_backup') HOSTNAME = os.environ['HOSTNAME'] level = logging.INFO diff --git a/restic_volume_backup/mail.py b/restic_compose_backup/mail.py similarity index 93% rename from restic_volume_backup/mail.py rename to restic_compose_backup/mail.py index 354f3c6..f086fe8 100644 --- a/restic_volume_backup/mail.py +++ b/restic_compose_backup/mail.py @@ -16,7 +16,7 @@ def main(): def send_mail(text): msg = MIMEText(text) - msg['Subject'] = "Message from restic-volume-backup" + msg['Subject'] = "Message from restic-compose-backup" msg['From'] = EMAIL_HOST_USER msg['To'] = ', '.join(EMAIL_SEND_TO) diff --git a/restic_volume_backup/restic.py b/restic_compose_backup/restic.py similarity index 97% rename from restic_volume_backup/restic.py rename to restic_compose_backup/restic.py index 554bbe8..95f2ef5 100644 --- a/restic_volume_backup/restic.py +++ b/restic_compose_backup/restic.py @@ -4,7 +4,7 @@ Restic commands import logging from typing import List from subprocess import Popen, PIPE -from restic_volume_backup import commands +from restic_compose_backup import commands logger = logging.getLogger(__name__) diff --git a/restic_volume_backup/utils.py b/restic_compose_backup/utils.py similarity index 95% rename from restic_volume_backup/utils.py rename to restic_compose_backup/utils.py index dd212d3..9087e70 100644 --- a/restic_volume_backup/utils.py +++ b/restic_compose_backup/utils.py @@ -2,7 +2,7 @@ import os from contextlib import contextmanager import docker -from restic_volume_backup.config import Config +from restic_compose_backup.config import Config TRUE_VALUES = ['1', 'true', 'True', True, 1] diff --git a/setup.py b/setup.py index 90c33d2..8480371 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,17 @@ from setuptools import setup, find_namespace_packages setup( - name="restic-volume-backup", - url="https://github.com/ZettaIO/restic-volume-backup", - version="1.0.0", + name="restic-compose-backup", + url="https://github.com/ZettaIO/restic-compose-backup", + version="0.2.0", author="Einar Forselv", author_email="eforselv@gmail.com", - packages=find_namespace_packages(include=['restic_volume_backup']), + packages=find_namespace_packages(include=['restic_compose_backup']), install_requires=[ 'docker==3.7.2', ], entry_points={'console_scripts': [ - 'restic-volume-backup = restic_volume_backup.cli:main', - 'rvb = restic_volume_backup.cli:main', + 'restic-compose-backup = restic_compose_backup.cli:main', + 'rcb = restic_compose_backup.cli:main', ]}, ) diff --git a/tests/fixtures.py b/tests/fixtures.py index 674ba5c..88ff692 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -35,7 +35,7 @@ def containers(project="default", containers=[]): 'Id': container.get('id', generate_sha256()), 'Name': container.get('service') + '_' + ''.join(random.choice(string.ascii_lowercase) for i in range(16)), 'Config': { - 'Image': 'restic-volume-backup_backup', + 'Image': 'restic-compose-backup_backup', 'Labels': { 'com.docker.compose.oneoff': 'False', 'com.docker.compose.project': project, diff --git a/tests/tests.py b/tests/tests.py index f16a871..56e5e0b 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -3,11 +3,11 @@ import os import unittest from unittest import mock -from restic_volume_backup import utils -from restic_volume_backup.containers import RunningContainers +from restic_compose_backup import utils +from restic_compose_backup.containers import RunningContainers import fixtures -list_containers_func = 'restic_volume_backup.utils.list_containers' +list_containers_func = 'restic_compose_backup.utils.list_containers' class ResticBackupTests(unittest.TestCase): @@ -88,7 +88,7 @@ class ResticBackupTests(unittest.TestCase): { 'service': 'web', 'labels': { - 'restic-volume-backup.volumes': True, + 'restic-compose-backup.volumes': True, }, 'mounts': [{ 'Source': 'test', @@ -99,7 +99,7 @@ class ResticBackupTests(unittest.TestCase): { 'service': 'mysql', 'labels': { - 'restic-volume-backup.mysql': True, + 'restic-compose-backup.mysql': True, }, 'mounts': [{ 'Source': 'data', @@ -119,7 +119,7 @@ class ResticBackupTests(unittest.TestCase): { 'service': 'web', 'labels': { - 'restic-volume-backup.include': 'media', + 'restic-compose-backup.include': 'media', }, 'mounts': [ { @@ -151,7 +151,7 @@ class ResticBackupTests(unittest.TestCase): { 'service': 'web', 'labels': { - 'restic-volume-backup.exclude': 'stuff', + 'restic-compose-backup.exclude': 'stuff', }, 'mounts': [ { @@ -187,7 +187,7 @@ class ResticBackupTests(unittest.TestCase): { 'service': 'backup_runner', 'labels': { - 'restic-volume-backup.backup_process': 'True', + 'restic-compose-backup.backup_process': 'True', }, }, ]