Commit 73d56f9f authored by Tim Bleimehl's avatar Tim Bleimehl 🤸🏼
Browse files

wip

parent 4d69957f
......@@ -9,4 +9,45 @@ docker exec mysql /usr/bin/psql -Atx postgresql://postgres:mysupersavepw@localho
INSERT INTO coda_ps_test_scheme.my_table(id,firstname) VALUES (1,'Anna'); \
INSERT INTO coda_ps_test_scheme.my_table(id,firstname) VALUES (2,'Thomas'); \
commit;"
```
\ No newline at end of file
```
# Issue with multiple databases in k8s
Labels are not corretly assigned
```
/bin/python3 /home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/cli.py backup kubernetes --all-namespaces
Container(id='c629b052-bc93-4781-af6f-a13b682e66e8', name='mariadb01-0', backup_labels={<Label 'backup.dzd-ev.de/backup_dir=./backups'>: <Label 'backup.dzd-ev.de/backup_dir=./backups'>, <Label 'backup.dzd-ev.de/host=127.0.0.1'>: <Label 'backup.dzd-ev.de/host=127.0.0.1'>, <Label 'backup.dzd-ev.de/databases=None'>: <Label 'backup.dzd-ev.de/databases=None'>, <Label 'backup.dzd-ev.de/password=None'>: <Label 'backup.dzd-ev.de/password=supersavepw'>, <Label 'backup.dzd-ev.de/type=None'>: <Label 'backup.dzd-ev.de/type=postgres'>, <Label 'backup.dzd-ev.de/username=None'>: <Label 'backup.dzd-ev.de/username=postgres'>, <Label 'backup.dzd-ev.de/enabled=False'>: <Label 'backup.dzd-ev.de/enabled=True'>, <Label 'backup.dzd-ev.de/retention_daily=7'>: <Label 'backup.dzd-ev.de/retention_daily=7'>, <Label 'backup.dzd-ev.de/retention_manual=4'>: <Label 'backup.dzd-ev.de/retention_manual=4'>, <Label 'backup.dzd-ev.de/retention_monthly=12'>: <Label 'backup.dzd-ev.de/retention_monthly=12'>, <Label 'backup.dzd-ev.de/retention_weekly=4'>: <Label 'backup.dzd-ev.de/retention_weekly=4'>, <Label 'backup.dzd-ev.de/retention_yearly=3'>: <Label 'backup.dzd-ev.de/retention_yearly=3'>}, other_labels={<Label 'controller-revision-hash=mariadb01-6844bc5dc7'>: <Label 'controller-revision-hash=mariadb01-6844bc5dc7'>, <Label 'statefulset.kubernetes.io/pod-name=mariadb01-0'>: <Label 'statefulset.kubernetes.io/pod-name=mariadb01-0'>, <Label 'workload.user.cattle.io/workloadselector=apps.statefulset-default-mariadb01'>: <Label 'workload.user.cattle.io/workloadselector=apps.statefulset-default-mariadb01'>}, desc={'apiVersion': 'v1', 'kind': 'Pod', 'metadata': {'creationTimestamp': '2022-01-19T13:41:16Z', 'generateName': 'mariadb01-', 'labels': {'controller-revision-hash': 'mariadb01-6844bc5dc7', 'statefulset.kubernetes.io/pod-name': 'mariadb01-0', 'workload.user.cattle.io/workloadselector': 'apps.statefulset-default-mariadb01'}, 'name': 'mariadb01-0', 'namespace': 'default', 'ownerReferences': [{'apiVersion': 'apps/v1', 'blockOwnerDeletion': True, 'controller': True, 'kind': 'StatefulSet', 'name': 'mariadb01', 'uid': '8b9a22b5-e787-4b8e-90a2-44b57a6d134f'}], 'resourceVersion': '953431', 'uid': 'c629b052-bc93-4781-af6f-a13b682e66e8'}, 'spec': {'containers': [{'env': [{'name': 'MYSQL_ROOT_PASSWORD', 'value': '498zrthfwejfef'}], 'image': 'mariadb:10', 'imagePullPolicy': 'Always', 'name': 'mariadb01', 'ports': [{'containerPort': 3306, 'hostPort': 3308, 'name': 'port3308', 'protocol': 'TCP'}], 'resources': {}, 'terminationMessagePath': '/dev/termination-log', 'terminationMessagePolicy': 'File', 'volumeMounts': [{'mountPath': '/var/run/secrets/kubernetes.io/serviceaccount', 'name': 'kube-api-access-rv57j', 'readOnly': True}]}], 'dnsPolicy': 'ClusterFirst', 'enableServiceLinks': True, 'hostname': 'mariadb01-0', 'nodeName': 'local-node', 'preemptionPolicy': 'PreemptLowerPriority', 'priority': 0, 'restartPolicy': 'Always', 'schedulerName': 'default-scheduler', 'securityContext': {}, 'serviceAccount': 'default', 'serviceAccountName': 'default', 'terminationGracePeriodSeconds': 30, 'tolerations': [{'effect': 'NoExecute', 'key': 'node.kubernetes.io/not-ready', 'operator': 'Exists', 'tolerationSeconds': 300}, {'effect': 'NoExecute', 'key': 'node.kubernetes.io/unreachable', 'operator': 'Exists', 'tolerationSeconds': 300}], 'volumes': [{'name': 'kube-api-access-rv57j', 'projected': {'defaultMode': 420, 'sources': [{'serviceAccountToken': {'expirationSeconds': 3607, 'path': 'token'}}, {'configMap': {'items': [{'key': 'ca.crt', 'path': 'ca.crt'}], 'name': 'kube-root-ca.crt'}}, {'downwardAPI': {'items': [{'fieldRef': {'apiVersion': 'v1', 'fieldPath': 'metadata.namespace'}, 'path': 'namespace'}]}}]}}]}, 'status': {'conditions': [{'lastProbeTime': None, 'lastTransitionTime': '2022-01-19T13:41:16Z', 'status': 'True', 'type': 'Initialized'}, {'lastProbeTime': None, 'lastTransitionTime': '2022-01-24T08:47:09Z', 'status': 'True', 'type': 'Ready'}, {'lastProbeTime': None, 'lastTransitionTime': '2022-01-24T08:47:09Z', 'status': 'True', 'type': 'ContainersReady'}, {'lastProbeTime': None, 'lastTransitionTime': '2022-01-19T13:41:16Z', 'status': 'True', 'type': 'PodScheduled'}], 'containerStatuses': [{'containerID': 'containerd://6dccb61553b7916bb028f17e56a8c46920a084c2d276736290725724a732d15d', 'image': 'docker.io/library/mariadb:10', 'imageID': 'docker.io/library/mariadb@sha256:5a37e65a6414d78f60d523c4ddcf93d715854337beb46f8beeb1a23d83262184', 'lastState': {'terminated': {'containerID': 'containerd://d128bb5e383e0131dd4cdba092f34e231021768e49426cdaa249e4af8af01589', 'exitCode': 255, 'finishedAt': '2022-01-24T08:46:52Z', 'reason': 'Unknown', 'startedAt': '2022-01-23T10:49:37Z'}}, 'name': 'mariadb01', 'ready': True, 'restartCount': 5, 'started': True, 'state': {'running': {'startedAt': '2022-01-24T08:47:08Z'}}}], 'hostIP': '172.17.0.2', 'phase': 'Running', 'podIP': '10.42.0.42', 'podIPs': [{'ip': '10.42.0.42'}], 'qosClass': 'BestEffort', 'startTime': '2022-01-19T13:41:16Z'}}, parent={'apiVersion': 'apps/v1', 'kind': 'Deployment', 'metadata': {'annotations': {'deployment.kubernetes.io/revision': '3'}, 'creationTimestamp': '2022-01-24T15:24:28Z', 'generation': 3, 'labels': {'backup.dzd-ev.de/enabled': 'true', 'backup.dzd-ev.de/password': 'supersavepw', 'backup.dzd-ev.de/type': 'postgres', 'backup.dzd-ev.de/username': 'postgres', 'workload.user.cattle.io/workloadselector': 'apps.deployment-my-namespace-postgres01'}, 'name': 'postgres01', 'namespace': 'my-namespace', 'resourceVersion': '1081236', 'uid': 'd26d382e-1f5f-4749-b077-20424a0d8bbc'}, 'spec': {'progressDeadlineSeconds': 600, 'replicas': 1, 'revisionHistoryLimit': 10, 'selector': {'matchLabels': {'workload.user.cattle.io/workloadselector': 'apps.deployment-my-namespace-postgres01'}}, 'strategy': {'rollingUpdate': {'maxSurge': '25%', 'maxUnavailable': '25%'}, 'type': 'RollingUpdate'}, 'template': {'metadata': {'annotations': {'cattle.io/timestamp': '2022-01-24T16:01:03Z'}, 'creationTimestamp': None, 'labels': {'workload.user.cattle.io/workloadselector': 'apps.deployment-my-namespace-postgres01'}}, 'spec': {'affinity': {}, 'containers': [{'env': [{'name': 'POSTGRES_PASSWORD', 'value': 'supersavepw'}], 'image': 'postgres:12', 'imagePullPolicy': 'Always', 'name': 'container-0', 'resources': {}, 'terminationMessagePath': '/dev/termination-log', 'terminationMessagePolicy': 'File'}], 'dnsPolicy': 'ClusterFirst', 'restartPolicy': 'Always', 'schedulerName': 'default-scheduler', 'securityContext': {}, 'terminationGracePeriodSeconds': 30}}}, 'status': {'availableReplicas': 1, 'conditions': [{'lastTransitionTime': '2022-01-24T15:24:47Z', 'lastUpdateTime': '2022-01-24T15:24:47Z', 'message': 'Deployment has minimum availability.', 'reason': 'MinimumReplicasAvailable', 'status': 'True', 'type': 'Available'}, {'lastTransitionTime': '2022-01-24T15:24:28Z', 'lastUpdateTime': '2022-01-24T16:01:06Z', 'message': 'ReplicaSet "postgres01-66646fbcc5" has successfully progressed.', 'reason': 'NewReplicaSetAvailable', 'status': 'True', 'type': 'Progressing'}], 'observedGeneration': 3, 'readyReplicas': 1, 'replicas': 1, 'updatedReplicas': 1}}, kubernetes_namespace='default')
backup.dzd-ev.de/type=postgres
True
[INFO] Start database backup...
Traceback (most recent call last):
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/cli.py", line 497, in <module>
cli_root()
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/tim/.local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/cli.py", line 214, in backup_kubernetes
bu.backup(
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/backupper.py", line 96, in backup
databases = self.list_databases()
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/backupper.py", line 80, in list_databases
result = self.executer.container_exec(command=self.get_list_database_command())
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/executer.py", line 47, in container_exec
return self.exec(exec_command)
File "/home/tim/Repos/git.connect.dzd-ev.de/DZDTools/CoDaBackup/CoDaBackup/executer.py", line 71, in exec
raise RuntimeError(
RuntimeError: ERROR CODE 1 on command
' kubectl exec -n default mariadb01-0 -- export PGPASSWORD=$supersavepw && psql -U postgres -h 127.0.0.1 -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" ':
error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "c79a99567f935b2bd12a7453bd74fe521ed8a1b32d98b6dd088c5d793dccae06": OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "export": executable file not found in $PATH: unknown
```
\ No newline at end of file
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