|
2 | 2 |
|
3 | 3 | Useful commands for working with the MariaDB operator. |
4 | 4 |
|
5 | | -Docs: <https://mariadb-operator.github.io/mariadb-operator/latest/> |
| 5 | +Docs: <https://github.com/mariadb-operator/mariadb-operator/blob/main/docs/README.md> |
6 | 6 |
|
7 | 7 | Repo: <https://github.com/mariadb-operator/mariadb-operator> |
8 | 8 |
|
@@ -40,6 +40,93 @@ ROOTPASSWORD=$(kubectl get secret -n openstack mariadb -o json | jq -r '.data["r |
40 | 40 | /usr/local/opt/mariadb/bin/mariadb-dump -h 127.0.0.1 --skip-ssl -u root --password=$ROOTPASSWORD $DB_TO_DUMP | gzip > $DB_TO_DUMP.sql.gz |
41 | 41 | ``` |
42 | 42 |
|
| 43 | +## Manual backup to a local .sql file |
| 44 | + |
| 45 | +``` bash |
| 46 | +kubectl exec -n openstack -it mariadb-0 -- mariadb-dump -u root -p"$MARIADB_ROOT_PASSWORD" \ |
| 47 | + --single-transaction \ |
| 48 | + --routines \ |
| 49 | + --triggers \ |
| 50 | + --all-databases > full-backup-$(date +%Y%m%d-%H%M).sql |
| 51 | +``` |
| 52 | + |
| 53 | +## Logical backup |
| 54 | + |
| 55 | +1. Create a MariaDB Operator backup manifest. In this example we'll call it `create-mariadb-backup.yaml` |
| 56 | + |
| 57 | +``` bash |
| 58 | +apiVersion: k8s.mariadb.com/v1alpha1 |
| 59 | +kind: Backup |
| 60 | +metadata: |
| 61 | + name: backup-pre-upgrade |
| 62 | +spec: |
| 63 | + mariaDbRef: |
| 64 | + name: mariadb |
| 65 | + storage: |
| 66 | + persistentVolumeClaim: |
| 67 | + resources: |
| 68 | + requests: |
| 69 | + storage: 20Gi |
| 70 | + accessModes: |
| 71 | + - ReadWriteOnce |
| 72 | +``` |
| 73 | + |
| 74 | +1. Apply the manifest: |
| 75 | + |
| 76 | +``` bash |
| 77 | +$ kubectl apply -f create-mariadb-backup.yaml |
| 78 | +backup.k8s.mariadb.com/backup-pre-upgrade created |
| 79 | +``` |
| 80 | + |
| 81 | +1. Check and wait until the backup has been completed: |
| 82 | + |
| 83 | +``` bash |
| 84 | +$ kubectl get backup.k8s.mariadb.com/backup-pre-upgrade |
| 85 | +NAME COMPLETE STATUS MARIADB AGE |
| 86 | +backup-pre-upgrade True Success mariadb 26s |
| 87 | +``` |
| 88 | + |
| 89 | +``` bash |
| 90 | +$ kubectl describe backup.k8s.mariadb.com/backup-pre-upgrade |
| 91 | +Name: backup-pre-upgrade |
| 92 | +Namespace: openstack |
| 93 | +Labels: <none> |
| 94 | +Annotations: <none> |
| 95 | +API Version: k8s.mariadb.com/v1alpha1 |
| 96 | +Kind: Backup |
| 97 | +Metadata: |
| 98 | + Creation Timestamp: 2025-10-21T14:19:28Z |
| 99 | + Generation: 2 |
| 100 | + Resource Version: 299003488 |
| 101 | + UID: 6f1481c0-9cc6-46c3-98c4-e64390b09aed |
| 102 | +Spec: |
| 103 | + Backoff Limit: 5 |
| 104 | + Compression: none |
| 105 | + Ignore Global Priv: true |
| 106 | + Log Level: info |
| 107 | + Maria Db Ref: |
| 108 | + Name: mariadb |
| 109 | + Wait For It: true |
| 110 | + Max Retention: 720h0m0s |
| 111 | + Restart Policy: OnFailure |
| 112 | + Service Account Name: backup-pre-upgrade |
| 113 | + Storage: |
| 114 | + Persistent Volume Claim: |
| 115 | + Access Modes: |
| 116 | + ReadWriteOnce |
| 117 | + Resources: |
| 118 | + Requests: |
| 119 | + Storage: 20Gi |
| 120 | +Status: |
| 121 | + Conditions: |
| 122 | + Last Transition Time: 2025-10-21T14:19:38Z |
| 123 | + Message: Success |
| 124 | + Reason: JobComplete |
| 125 | + Status: True |
| 126 | + Type: Complete |
| 127 | +Events: <none> |
| 128 | +``` |
| 129 | + |
43 | 130 | ## Restore from a point in time backup |
44 | 131 |
|
45 | 132 | This assumes you have backups enabled with regularly scheduled backups: <https://github.com/mariadb-operator/mariadb-operator/blob/main/docs/BACKUP.md/#scheduling> |
|
0 commit comments