Commit 26f14d55 authored by Tim Bleimehl's avatar Tim Bleimehl 🤸🏼
Browse files

wip

parent 28842d25
......@@ -44,13 +44,13 @@ database_type_backupper_mapping: Dict[str, Type[BaseBackupper]] = {
help="Enable debug logging",
default=False,
)
def cli(debug):
def backup_cli(debug):
if debug:
click.echo(f"Debug mode is on")
log.setLevel("DEBUG")
@cli.command()
@backup_cli.command()
@click.option(
"--mode",
default="Docker",
......@@ -130,7 +130,7 @@ def backup_now(
)
@cli.command()
@backup_cli.command()
@click.option(
"--namespace",
"-n",
......@@ -144,7 +144,7 @@ def backup_now(
default=False,
help="If we should search for pods, to be backed up, in all namespaces. When used `--namespace` will be ignored.",
)
def k8s(namespace, all_namespaces):
def kubernetes(namespace, all_namespaces):
"""Backup databases in a kubernetes environment"""
from container_helper import ContainerHelper
......@@ -175,14 +175,9 @@ def k8s(namespace, all_namespaces):
bu.retention.rotate_existing_backups()
@cli.group()
def docker():
pass
@docker.command()
@backup_cli.command()
@click.argument("target-dir", default="backup/")
def backup(target_dir):
def docker(target_dir):
"""Backup databases in a docker environment"""
for container_name in ContainerHelper.docker_get_container_to_be_backed_up():
......@@ -223,22 +218,107 @@ def backup(target_dir):
bu.retention.rotate_existing_backups()
@docker.command(name="restore")
def docker_restore():
print("RESTORE")
@click.group()
@click.option(
"--debug/--no-debug",
help="Enable debug logging",
default=False,
)
def restore_cli(debug):
if debug:
click.echo(f"Debug mode is on")
log.setLevel("DEBUG")
@cli.command()
@restore_cli.command()
@click.option(
"--mode",
default="docker",
default="Docker",
prompt="How is your DB running?",
help="Environment the database is running in: 'Docker', 'k8s'",
type=click.Choice(["docker", "k8s"], case_sensitive=False),
help="Environment the database is running in: 'Docker', 'k8s', 'native'",
type=click.Choice(["docker", "k8s", "native"], case_sensitive=False),
)
@click.option(
"--container-identifier",
prompt="Container/pod name(s) (seperated by comma)? (Ignore question in `native` mode)",
help="The Docker container name/id (as in `docker ps`) or kubernetes pod name.",
)
@click.option(
"--database-type",
default="mysql",
prompt="Database type?",
help="Do we backup a mysql/maria db or a postgres db?",
type=click.Choice(["mysql", "postgres"], case_sensitive=False),
)
@click.option(
"--database-host",
default="127.0.0.1",
prompt="Database host?",
help="Hostname or IP where the database is running. In non `native`-mode this will be likely the 'localhost'/' 127.0.0.1' (default value)",
)
@click.option(
"--database-user",
default="root",
prompt="Database user?",
help="User to access the database?",
)
@click.option(
"--database-password",
hide_input=True,
prompt="Database password?",
help="Password to access the database?",
)
@click.option(
"--database-name",
default="",
prompt="Database(s) to backup ('mydb' or ['mydb01', 'mydb02'])? Leave empty for all DBs.",
help="The Databases to backup. We can select a specific database by name . e.g. 'my_database01' or a list of databases e.b. ['mydb01', 'mydb02']. If left empty all databses accessable for the user will be backuped.",
)
@click.option(
"--backup-name",
prompt="Name of the backup?",
help="Name of the backup as listed in `coda-restore <mode> list <database instance name>`?",
)
def restore_now(
mode,
container_identifier,
database_type,
database_host,
database_user,
database_password,
database_name,
backup_name,
):
pass
@restore_cli.command()
@click.option(
"--namespace",
"-n",
type=str,
default="default",
help="Define the namespace we should search for database pods to be backed up.",
)
@click.option(
"--all-namespaces",
"-all-namespaces",
default=False,
help="If we should search for pods, to be backed up, in all namespaces. When used `--namespace` will be ignored.",
)
@click.option(
"--pod-name",
hide_input=False,
help="Name of the pod/container the to be restored database runs in?",
)
@click.option(
"--backup-name",
hide_input=False,
help="Name of the backup (find via coda-restore kubernetes list)?",
)
def restore():
def kubernetes():
pass
if __name__ == "__main__":
cli()
backup_cli()
......@@ -14,7 +14,11 @@ class Label:
_BASE_LABEL: str = config.DATABASE_CONTAINER_LABEL_BASE_KEY
def __init__(
self, label: str, type: Type, possible_values: List = None, default: Any = None
self,
label: str,
type: Type,
possible_values: List = None,
default: Any = None,
):
key, *val = label.split("=")
self.key = f"{self._BASE_LABEL}/{key}"
......
......@@ -84,8 +84,10 @@ Thats it. We now have a directory `./backups/` in front of us, with all database
* (WIP) Restore Wizard
* (WIP) Neo4j support
* (WIP) Database auth via Docker/K8s Secrets
* (Planned) Create database if not existent via label conf (checked/executed when pod starts via https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/)
* (Planned) Email notification
* (Planned) Support of docker and kubernetes secrets for providing database auth
* (Idea) restore by label (checked/executed when pod starts via https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/)
* (Idea) Matrix notifications
* (Idea) [Podman](https://podman.io/) support. Your help is greatly appreciated. Should be easy or maybe no work at all
* (Idea) [LCX](https://linuxcontainers.org/) support. Help needed!
......
......@@ -27,6 +27,9 @@ setup(
},
setup_requires=["setuptools_scm"],
entry_points={
"console_scripts": ["coda-backup=CoDaBackup.cli:cli"],
"console_scripts": [
"coda-backup=CoDaBackup.cli:backup_cli",
"coda-restore=CoDaBackup.cli:restore_cli",
],
},
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment