Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physical backups via mariabackup #11

Open
mmontes11 opened this issue Nov 3, 2022 · 9 comments · Fixed by #15 · May be fixed by #273
Open

Physical backups via mariabackup #11

mmontes11 opened this issue Nov 3, 2022 · 9 comments · Fixed by #15 · May be fixed by #273
Labels
backup feature priority-long-term To be resolved in the long term

Comments

@mmontes11
Copy link
Member

mmontes11 commented Nov 3, 2022

MariaDB has its own backup command to perform backups, we should migrate to use it:

Usage can be found here under the Creating backups with Mariabackup section:

docker run --user mysql -v some-mariadb-socket:/var/run/mysqld -v some-mariadb-backup:/backup -v /my/own/datadir:/var/lib/mysql --rm mariadb:latest mariabackup --backup --target-dir=/backup
@mmontes11 mmontes11 added backup enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Nov 3, 2022
@grooverdan
Copy link
Contributor

There's still a role for the venerable mysqldump as a logical backup as its a good mitigator for the odd corruption bugs of database tables that mariabackup (and others like aria-hotcopy) physical backup programs don't mitigate. So I'd consider an addition rather than replacement.

@mmontes11
Copy link
Member Author

mmontes11 commented Nov 4, 2022

@grooverdan thanks for the clarification, it does makes sense. We could extend our CRD so the user could choose the type of backup, defaulting to the logical one:

apiVersion: database.mmontes.io/v1alpha1
kind: BackupMariaDB
metadata:
  name: backup
spec:
  type: (logical | physical)
  mariaDbRef:
    name: mariadb
  storage:
    persistentVolumeClaim:
      resources:
        requests:
          storage: 100Mi
      storageClassName: standard
      accessModes:
        - ReadWriteOnce

@mmontes11
Copy link
Member Author

Reopening, see:

@mmontes11 mmontes11 reopened this May 6, 2023
@mmontes11 mmontes11 added priority-long-term To be resolved in the long term and removed enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels May 7, 2023
@mmontes11
Copy link
Member Author

mmontes11 commented Sep 11, 2023

I've managed to restore a physical backup in a MariaDB instance with Galera enabled. Steps followed:

  • Provision a MariaDB instance with Galera enabled
apiVersion: mariadb.mmontes.io/v1alpha1
kind: MariaDB
metadata:
  name: mariadb-galera
spec:
  rootPasswordSecretKeyRef:
    name: mariadb
    key: root-password

  database: mariadb
  username: mariadb
  passwordSecretKeyRef:
    name: mariadb
    key: password

  image:
    repository: mariadb
    tag: "11.0.3"
    pullPolicy: IfNotPresent

  port: 3306

  replicas: 3
     
  galera:
    enabled: true

  volumeClaimTemplate:
    resources:
      requests:
        storage: 1Gi
    accessModes:
      - ReadWriteOnce
  volumes: 
    - name: mariabackup
      persistentVolumeClaim:
        claimName: mariabackup
  volumeMounts: 
    - name: mariabackup
      mountPath: /var/mariadb/backup/
  • Populate the database using SqlJobs
  • Shell into mariadb-galera-0 and run:
mariabackup --backup --target-dir=/var/mariadb/backup/ --user=root --password=mariadb
mariabackup --prepare --target-dir=/var/mariadb/backup/
  • Delete the MariaDB instance and its PVCs
  • Create another MariaDB with a mariabackup init container
apiVersion: mariadb.mmontes.io/v1alpha1
kind: MariaDB
metadata:
  name: mariadb-galera
spec:
  rootPasswordSecretKeyRef:
    name: mariadb
    key: root-password

  database: mariadb
  username: mariadb
  passwordSecretKeyRef:
    name: mariadb
    key: password

  image:
    repository: mariadb
    tag: "11.0.3"
    pullPolicy: IfNotPresent

  port: 3306

  replicas: 3
     
  galera:
    enabled: true

  # See: https://mariadb.com/kb/en/full-backup-and-restore-with-mariabackup/
  initContainers:
    - image:
        repository: mariadb
        tag: "11.0.3"
        pullPolicy: IfNotPresent
      args:
        - mariabackup 
        - --copy-back 
        - --target-dir=/var/mariadb/backup/

  volumeClaimTemplate:
    resources:
      requests:
        storage: 1Gi
    accessModes:
      - ReadWriteOnce
  volumes: 
    - name: mariabackup
      persistentVolumeClaim:
        claimName: mariabackup
  volumeMounts: 
    - name: mariabackup
      mountPath: /var/mariadb/backup/
  • Shell into any MariaDB Pod (mariadb-galera-0, mariadb-galera-1 or mariadb-galera-2) and make sure the tables and data are there:
MariaDB [(none)]> use mariadb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mariadb]> show tables;
+-------------------+
| Tables_in_mariadb |
+-------------------+
| repos             |
| stars             |
| users             |
+-------------------+
3 rows in set (0.000 sec)

MariaDB [mariadb]> select * from stars;
+-----+---------+---------+
| id  | user_id | repo_id |
+-----+---------+---------+
| 318 |       3 |       1 |
| 383 |       9 |       1 |
| 335 |      12 |       4 |
| 380 |      15 |       7 |
| 277 |      18 |       4 |
| 391 |      18 |       7 |
+-----+---------+---------+
6 rows in set (0.000 sec)

@grooverdan
Copy link
Contributor

Can mariadb-backup backup be used in the final version - symlink and naming. Exists on 10.4+

@mmontes11
Copy link
Member Author

Can mariadb-backup backup be used in the final version

@grooverdan not sure If I'm understanding. If I utilize mariabackup within the mariadb:11.0.3 container, wouldn't that mean I'm already working with the latest version?

@grooverdan
Copy link
Contributor

Yep, mariabackup is the older version of name. It hasn't been deprecated or removed but at the moment its a symlink so will eventually deprecate out.

@mmontes11
Copy link
Member Author

Great, I've updated the example to use maria-backup:

Maybe this docs need to be updated as well?:

@mmontes11
Copy link
Member Author

See relevant PR for mariadb-docker which automatically restores physical *.tar.gz backups provided under /docker-entrypoint-initdb.d:

@mmontes11 mmontes11 changed the title Use mariabackup instead of mysqldump Physical backups via mariabackup Oct 8, 2023
@mmontes11 mmontes11 linked a pull request Dec 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backup feature priority-long-term To be resolved in the long term
Projects
None yet
2 participants