Output backup destination path with output command

This commit is contained in:
Jannik 2020-05-26 10:42:29 +02:00
parent 8b934dc12f
commit f59a046bbc
3 changed files with 22 additions and 6 deletions

View File

@ -91,12 +91,12 @@ def status(config, containers):
if container.volume_backup_enabled:
for mount in container.filter_mounts():
logger.info(' - volume: %s', mount.source)
logger.info(' - volume: %s -> %s', mount.source, container.get_volume_backup_destination(mount, '/volumes'))
if container.database_backup_enabled:
instance = container.instance
ping = instance.ping()
logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0)
logger.info(' - %s (is_ready=%s) -> %s', instance.container_type, ping == 0, instance.backup_destination_path())
if ping != 0:
logger.error("Database '%s' in service %s cannot be reached",
instance.container_type, container.service_name)

View File

@ -224,12 +224,15 @@ class Container:
volumes = {}
for mount in mounts:
volumes[mount.source] = {
'bind': str(Path(source_prefix) / self.service_name / Path(utils.strip_root(mount.destination))),
'bind': self.get_volume_backup_destination(mount, source_prefix),
'mode': mode,
}
return volumes
def get_volume_backup_destination(self, mount, source_prefix) -> str:
return str(Path(source_prefix) / self.service_name / Path(utils.strip_root(mount.destination)))
def get_credentials(self) -> dict:
"""dict: get credentials for the service"""
raise NotImplementedError("Base container class don't implement this")
@ -242,6 +245,10 @@ class Container:
"""Back up this service"""
raise NotImplementedError("Base container class don't implement this")
def backup_destination_path(self) -> str:
"""Return the path backups will be saved at"""
raise NotImplementedError("Base container class don't implement this")
def dump_command(self) -> list:
"""list: create a dump command restic and use to send data through stdin"""
raise NotImplementedError("Base container class don't implement this")

View File

@ -48,10 +48,13 @@ class MariadbContainer(Container):
with utils.environment('MYSQL_PWD', creds['password']):
return restic.backup_from_stdin(
config.repository,
f'/databases/{self.service_name}/all_databases.sql',
self.backup_destination_path(),
self.dump_command(),
)
def backup_destination_path(self) -> str:
return f'/databases/{self.service_name}/all_databases.sql'
class MysqlContainer(Container):
container_type = 'mysql'
@ -94,10 +97,13 @@ class MysqlContainer(Container):
with utils.environment('MYSQL_PWD', creds['password']):
return restic.backup_from_stdin(
config.repository,
f'/databases/{self.service_name}/all_databases.sql',
self.backup_destination_path(),
self.dump_command(),
)
def backup_destination_path(self) -> str:
return f'/databases/{self.service_name}/all_databases.sql'
class PostgresContainer(Container):
container_type = 'postgres'
@ -141,6 +147,9 @@ class PostgresContainer(Container):
with utils.environment('PGPASSWORD', creds['password']):
return restic.backup_from_stdin(
config.repository,
f"/databases/{self.service_name}/{creds['database']}.sql",
self.backup_destination_path(),
self.dump_command(),
)
def backup_destination_path(self) -> str:
return f"/databases/{self.service_name}/{self.get_credentials()['database']}.sql"