Rename project

This commit is contained in:
Einar Forselv 2019-12-03 09:40:02 +01:00
parent 2a861b0519
commit fc5c6cc914
18 changed files with 59 additions and 57 deletions

View File

@ -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 .

View File

@ -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

View File

@ -1 +1 @@
1 * * * * source /env.sh && rvb backup > /proc/1/fd/1
1 * * * * source /env.sh && rcb backup > /proc/1/fd/1

View File

@ -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

View File

@ -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__)

View File

@ -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'],

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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)

View File

@ -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__)

View File

@ -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]

View File

@ -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',
]},
)

View File

@ -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,

View File

@ -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',
},
},
]