Commit 993be7f1 authored by Tim Bleimehl's avatar Tim Bleimehl 🤸🏼
Browse files

wip

parent 03a310af
......@@ -251,7 +251,8 @@ class BaseBackupper:
user_password = user_password.strip()
# lets go
if not user_name in existing_users:
# user does not exists. lest create it
# user does not exists. lets create it
log.info(f"Create user '{user_name}'@'{self.container.name}' ")
self.executer.container_exec(
command=self.get_create_user_command(
username=user_name,
......@@ -262,6 +263,7 @@ class BaseBackupper:
)
if not database_name in existing_databases:
# database does not exists. lets create it
log.info(f"Create database '{database_name}'@'{self.container.name}' ")
self.executer.container_exec(
command=self.get_create_database_command(
database_name,
......
......@@ -19,8 +19,7 @@ if __name__ == "__main__":
sys.path.append(os.path.normpath(SCRIPT_DIR))
from backup_manager import RetentionType, Backup
from executer import Executer
from backup_manager import RetentionType
from backupper import (
BaseBackupper,
MySQLBackupper,
......@@ -534,10 +533,40 @@ def auto_create(debug):
log.setLevel("DEBUG")
@auto_create.command(name="now")
def auto_create_now():
@auto_create.command(name="kubernetes")
@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",
is_flag=True,
default=False,
help="If we should search for pods, to be backed up, in all namespaces. When used `--namespace` will be ignored.",
)
def auto_create_kubernetes(namespace, all_namespaces):
# you are here. maybe we dont new "now" command and instead a kubernetes and a docker version
raise NotImplementedError
from container_helper import ContainerHelper
count_db_instances = 0
count_dbs = 0
for pod in ContainerHelper.kubernetes_get_pods_to_be_backed_up(
namespace=namespace, all_namespaces=all_namespaces
):
if pod.coda_labels[ValidLabels.enabled].val:
BackupperClass = database_type_backupper_mapping[
pod.coda_labels[ValidLabels.database_type].val
]
bu: BaseBackupper = BackupperClass(pod)
bu.auto_create()
click.echo(
f"\nBackuped {count_dbs} database(s) in {count_db_instances} instance(s)"
)
if __name__ == "__main__":
......
......@@ -63,7 +63,9 @@ class Container:
backup_name=kubectl_get_item_result["metadata"]["name"],
coda_labels=ValidLabels.valid_labels_from_dict(
kubectl_get_item_result["metadata"]["labels"]
| kubectl_get_item_result["metadata"]["annotations"],
| kubectl_get_item_result["metadata"]["annotations"]
if "annotations" in kubectl_get_item_result["metadata"]
else {},
add_missing_default_labels=True,
),
other_labels=ValidLabels.non_valid_labels_from_dict(
......@@ -188,7 +190,11 @@ class ContainerHelper:
cls, pod: Container, parent_workload: Dict
) -> Container:
workload_backup_config_labels = ValidLabels.valid_labels_from_dict(
parent_workload["metadata"]["labels"], add_missing_default_labels=True
parent_workload["metadata"]["labels"]
| parent_workload["metadata"]["annotations"]
if "annotations" in parent_workload["metadata"]
else {},
add_missing_default_labels=True,
)
pod.coda_labels = pod.coda_labels | workload_backup_config_labels
......
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