Allow inclusion of project name in backup path
This commit is contained in:
parent
f59a046bbc
commit
18ddb173ac
|
@ -5,6 +5,7 @@
|
||||||
# DOCKER_CERT_PATH=''
|
# DOCKER_CERT_PATH=''
|
||||||
|
|
||||||
SWARM_MODE=true
|
SWARM_MODE=true
|
||||||
|
INCLUDE_PROJECT_NAME=false
|
||||||
|
|
||||||
RESTIC_REPOSITORY=/restic_data
|
RESTIC_REPOSITORY=/restic_data
|
||||||
RESTIC_PASSWORD=password
|
RESTIC_PASSWORD=password
|
||||||
|
|
|
@ -66,6 +66,7 @@ def status(config, containers):
|
||||||
logger.info("Status for compose project '%s'", containers.project_name)
|
logger.info("Status for compose project '%s'", containers.project_name)
|
||||||
logger.info("Repository: '%s'", config.repository)
|
logger.info("Repository: '%s'", config.repository)
|
||||||
logger.info("Backup currently running?: %s", containers.backup_process_running)
|
logger.info("Backup currently running?: %s", containers.backup_process_running)
|
||||||
|
logger.info("Include project name in backup path?: %s", utils.is_true(config.include_project_name))
|
||||||
logger.info("Checking docker availability")
|
logger.info("Checking docker availability")
|
||||||
|
|
||||||
utils.list_containers()
|
utils.list_containers()
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Config:
|
||||||
self.cron_schedule = os.environ.get('CRON_SCHEDULE') or self.default_crontab_schedule
|
self.cron_schedule = os.environ.get('CRON_SCHEDULE') or self.default_crontab_schedule
|
||||||
self.cron_command = os.environ.get('CRON_COMMAND') or self.default_backup_command
|
self.cron_command = os.environ.get('CRON_COMMAND') or self.default_backup_command
|
||||||
self.swarm_mode = os.environ.get('SWARM_MODE') or False
|
self.swarm_mode = os.environ.get('SWARM_MODE') or False
|
||||||
|
self.include_project_name = os.environ.get('INCLUDE_PROJECT_NAME') or False
|
||||||
|
|
||||||
# Log
|
# Log
|
||||||
self.log_level = os.environ.get('LOG_LEVEL')
|
self.log_level = os.environ.get('LOG_LEVEL')
|
||||||
|
|
|
@ -231,7 +231,17 @@ class Container:
|
||||||
return volumes
|
return volumes
|
||||||
|
|
||||||
def get_volume_backup_destination(self, mount, source_prefix) -> str:
|
def get_volume_backup_destination(self, mount, source_prefix) -> str:
|
||||||
return str(Path(source_prefix) / self.service_name / Path(utils.strip_root(mount.destination)))
|
destination = Path(source_prefix)
|
||||||
|
|
||||||
|
if utils.is_true(config.include_project_name):
|
||||||
|
project_name = self.project_name
|
||||||
|
if project_name != '':
|
||||||
|
destination /= project_name
|
||||||
|
|
||||||
|
destination /= self.service_name
|
||||||
|
destination /= Path(utils.strip_root(mount.destination))
|
||||||
|
|
||||||
|
return str(destination)
|
||||||
|
|
||||||
def get_credentials(self) -> dict:
|
def get_credentials(self) -> dict:
|
||||||
"""dict: get credentials for the service"""
|
"""dict: get credentials for the service"""
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from restic_compose_backup.containers import Container
|
from restic_compose_backup.containers import Container
|
||||||
from restic_compose_backup.config import Config
|
from restic_compose_backup.config import config, Config
|
||||||
from restic_compose_backup import (
|
from restic_compose_backup import (
|
||||||
commands,
|
commands,
|
||||||
restic,
|
restic,
|
||||||
|
@ -53,7 +55,17 @@ class MariadbContainer(Container):
|
||||||
)
|
)
|
||||||
|
|
||||||
def backup_destination_path(self) -> str:
|
def backup_destination_path(self) -> str:
|
||||||
return f'/databases/{self.service_name}/all_databases.sql'
|
destination = Path("/databases")
|
||||||
|
|
||||||
|
if utils.is_true(config.include_project_name):
|
||||||
|
project_name = self.project_name
|
||||||
|
if project_name != "":
|
||||||
|
destination /= project_name
|
||||||
|
|
||||||
|
destination /= self.service_name
|
||||||
|
destination /= "all_databases.sql"
|
||||||
|
|
||||||
|
return destination
|
||||||
|
|
||||||
|
|
||||||
class MysqlContainer(Container):
|
class MysqlContainer(Container):
|
||||||
|
@ -102,7 +114,17 @@ class MysqlContainer(Container):
|
||||||
)
|
)
|
||||||
|
|
||||||
def backup_destination_path(self) -> str:
|
def backup_destination_path(self) -> str:
|
||||||
return f'/databases/{self.service_name}/all_databases.sql'
|
destination = Path("/databases")
|
||||||
|
|
||||||
|
if utils.is_true(config.include_project_name):
|
||||||
|
project_name = self.project_name
|
||||||
|
if project_name != "":
|
||||||
|
destination /= project_name
|
||||||
|
|
||||||
|
destination /= self.service_name
|
||||||
|
destination /= "all_databases.sql"
|
||||||
|
|
||||||
|
return destination
|
||||||
|
|
||||||
|
|
||||||
class PostgresContainer(Container):
|
class PostgresContainer(Container):
|
||||||
|
@ -152,4 +174,14 @@ class PostgresContainer(Container):
|
||||||
)
|
)
|
||||||
|
|
||||||
def backup_destination_path(self) -> str:
|
def backup_destination_path(self) -> str:
|
||||||
return f"/databases/{self.service_name}/{self.get_credentials()['database']}.sql"
|
destination = Path("/databases")
|
||||||
|
|
||||||
|
if utils.is_true(config.include_project_name):
|
||||||
|
project_name = self.project_name
|
||||||
|
if project_name != "":
|
||||||
|
destination /= project_name
|
||||||
|
|
||||||
|
destination /= self.service_name
|
||||||
|
destination /= f"{self.get_credentials()['database']}.sql"
|
||||||
|
|
||||||
|
return destination
|
||||||
|
|
Loading…
Reference in New Issue