2019-12-03 00:29:41 +00:00
|
|
|
from restic_volume_backup.containers import Container
|
2019-12-03 04:00:47 +00:00
|
|
|
from restic_volume_backup.config import Config
|
2019-12-03 03:23:06 +00:00
|
|
|
from restic_volume_backup import (
|
|
|
|
commands,
|
|
|
|
restic,
|
|
|
|
)
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MariadbContainer(Container):
|
|
|
|
container_type = 'mariadb'
|
|
|
|
|
|
|
|
def get_credentials(self) -> dict:
|
|
|
|
"""dict: get credentials for the service"""
|
|
|
|
return {
|
|
|
|
'host': self.hostname,
|
|
|
|
'username': self.get_config_env('MYSQL_USER'),
|
|
|
|
'password': self.get_config_env('MYSQL_PASSWORD'),
|
|
|
|
'port': "3306",
|
|
|
|
}
|
|
|
|
|
|
|
|
def ping(self) -> bool:
|
|
|
|
"""Check the availability of the service"""
|
2019-12-03 00:47:15 +00:00
|
|
|
creds = self.get_credentials()
|
|
|
|
return commands.ping_mysql(
|
|
|
|
creds['host'],
|
|
|
|
creds['port'],
|
|
|
|
creds['username'],
|
|
|
|
creds['password'],
|
|
|
|
)
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
def dump_command(self) -> list:
|
|
|
|
"""list: create a dump command restic and use to send data through stdin"""
|
2019-12-03 03:23:06 +00:00
|
|
|
creds = self.get_credentials()
|
|
|
|
return [
|
|
|
|
"mysqldump",
|
|
|
|
f"--host={creds['host']}",
|
|
|
|
f"--port={creds['port']}",
|
|
|
|
f"--user={creds['username']}",
|
|
|
|
f"--password={creds['password']}",
|
|
|
|
"--all-databases",
|
|
|
|
]
|
|
|
|
|
|
|
|
def backup(self):
|
2019-12-03 04:00:47 +00:00
|
|
|
config = Config()
|
2019-12-03 03:23:06 +00:00
|
|
|
return restic.backup_from_stdin(
|
2019-12-03 04:00:47 +00:00
|
|
|
config.repository,
|
2019-12-03 03:23:06 +00:00
|
|
|
f'/backup/{self.service_name}',
|
|
|
|
self.dump_command(),
|
|
|
|
)
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MysqlContainer(Container):
|
|
|
|
container_type = 'mysql'
|
|
|
|
|
|
|
|
def get_credentials(self) -> dict:
|
|
|
|
"""dict: get credentials for the service"""
|
|
|
|
return {
|
|
|
|
'host': self.hostname,
|
|
|
|
'username': self.get_config_env('MYSQL_USER'),
|
|
|
|
'password': self.get_config_env('MYSQL_PASSWORD'),
|
|
|
|
'port': "3306",
|
|
|
|
}
|
|
|
|
|
|
|
|
def ping(self) -> bool:
|
|
|
|
"""Check the availability of the service"""
|
2019-12-03 00:47:15 +00:00
|
|
|
creds = self.get_credentials()
|
|
|
|
return commands.ping_mysql(
|
|
|
|
creds['host'],
|
|
|
|
creds['port'],
|
|
|
|
creds['username'],
|
|
|
|
creds['password'],
|
|
|
|
)
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
2019-12-03 03:23:06 +00:00
|
|
|
def backup(self):
|
|
|
|
print("SKIPPING")
|
|
|
|
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
class PostgresContainer(Container):
|
|
|
|
container_type = 'postgres'
|
|
|
|
|
|
|
|
def get_credentials(self) -> dict:
|
|
|
|
"""dict: get credentials for the service"""
|
|
|
|
return {
|
|
|
|
'host': self.hostname,
|
|
|
|
'username': self.get_config_env('POSTGRES_USER'),
|
|
|
|
'password': self.get_config_env('POSTGRES_PASSWORD'),
|
|
|
|
'port': "5432",
|
|
|
|
}
|
|
|
|
|
|
|
|
def ping(self) -> bool:
|
|
|
|
"""Check the availability of the service"""
|
2019-12-03 02:00:17 +00:00
|
|
|
creds = self.get_credentials()
|
|
|
|
return commands.ping_postgres(
|
|
|
|
creds['host'],
|
|
|
|
creds['port'],
|
|
|
|
creds['username'],
|
|
|
|
creds['password'],
|
|
|
|
)
|
2019-12-03 00:29:41 +00:00
|
|
|
|
|
|
|
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")
|
2019-12-03 03:23:06 +00:00
|
|
|
|
|
|
|
def backup(self):
|
|
|
|
print("SKIPPING")
|