Skip to content

Add Support to mariadbbackup - #273

Closed
harunkucuk5 wants to merge 16 commits into
mariadb-operator:mainfrom
harunkucuk5:hkucuk/maria-backup
Closed

harunkucuk5 wants to merge 16 commits into
mariadb-operator:mainfrom
harunkucuk5:hkucuk/maria-backup

Conversation

@harunkucuk5

@harunkucuk5 harunkucuk5 commented Nov 12, 2023 •

Copy link
Copy Markdown
Contributor

Closes #11

This PR adds mariadbbackup support.

Note: scheduled backups are not supported for now as the physical backup requires to be triggered on the database pod and when cronjob starts there is nothing that can trigger backup on the database pod. But for the on-demand backups mariadb-backup reconciler triggers the backup on the database pod

The new logic allows scheduled mariadbbackups. Thanks @kvaps.

logs from backup

 💾 Taking physical backup                                                                                                                                                                                                                                           
[00] 2023-12-26 20:22:06 Connecting to MariaDB server host: mariadb-repl-primary, user: root, password: set, port: not set, socket: /run/mysqld/mysqld.sock                                                                                                         
[00] 2023-12-26 20:22:06 Using server version 11.0.3-MariaDB-1:11.0.3+maria~ubu2204-log                                                                                                                                                                             
mariadb-backup based on MariaDB server 11.0.3-MariaDB debian-linux-gnu (aarch64)
...

[00] 2023-12-26 20:38:29         ...done                                                                                                                                                                                                                            
[00] 2023-12-26 20:38:29 Redo log (from LSN 443413019 to 443598086) was copied.                                                                                                                                                                                     
[00] 2023-12-26 20:38:29 completed OK!                                                                                                                                                                                                                              
📜 Backup completed                                                                                                                                                                                                                                                 
🧹 Cleaning up old backups
📜 Backup history
...
87M    /backup/mariabackup-2023-12-25T18:32:39Z                                                                                                                                                                                                                     
87M    /backup/mariabackup-2023-12-26T19:47:43Z                                                                                                                                                                                                                     
87M    /backup/mariabackup-2023-12-26T20:22:06Z

logs from restore

  Checking if a restore already performed...                                                                                                                                                                                                                          
 Cleaning current data folder...                                                                                                                                                                                                                                     
 Creating a temporary data folder...                                                                                                                                                                                                                                 
 Moving backup to the temporary data folder...                                                                                                                                                                                                                       
 sending incremental file list                                                                                                                                                                                                                                       
 ./                                                                                                                                                                                                                                                                  
 aria_log.00000001                                                                                                                                                                                                                                                   
 aria_log_control                                                                                                                                                                                                                                                    
 backup-my.cnf
 ...
 sent 90,102,988 bytes  received 4,233 bytes  25,744,920.29 bytes/sec                                                                                                                                                                                                
 total size is 90,064,114  speedup is 1.00                                                                                                                                                                                                                           
 Preparing backup...                                                                                                                                                                                                                                                 
 mariadb-backup based on MariaDB server 11.0.3-MariaDB debian-linux-gnu (aarch64)                                                                                                                                                                                    
 [00] 2023-12-26 20:25:30 cd to /var/lib/mysql/mariabackup/                                                                                                                                                                                                          
 [00] 2023-12-26 20:25:30 open files limit requested 0, set to 1048576                                                                                                                                                                                               
 [00] 2023-12-26 20:25:30 Renaming ./mysql/gtid_slave_pos.new to ./mysql/gtid_slave_pos.ibd
...
 [00] 2023-12-26 20:25:31 Last binlog file ./mariadb-repl-bin.000003, position 851                                                                                                                                                                                   
 [00] 2023-12-26 20:25:31 completed OK!                                                                                                                                                                                                                              
 Moving restored backup to the data directory...                                                                                                                                                                                                                     
 Removing temporary folder...                                                                                                                                                                                                                                        
 Creating a flag file to avoid multiple restoration after restart...                                                                                                                                                                                                 
 Changing ownership of the files to mysql...
...

image

image

image

image

@mmontes11
mmontes11 self-requested a review November 12, 2023 12:25

@mmontes11 mmontes11 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there @harunkucuk5 ! Huge kudos for starting working on this, looks promising. It will be a massive contribution for the project 🎖️ 💯 ❤️ 💯 ❤️ 🎖️

Note: scheduled backups are not supported for now as the physical backup requires to be triggered on the database pod and when cronjob starts there is nothing that can trigger backup on the database pod. But for the on-demand backups mariadb-backup reconciler triggers the backup on the database pod

Regarding the scheduled backups, I would say don't stress too much, we can take care of it as a separate issue or even implement it myself later. Having mariabackup support is a huge step forward.

I think this PR is attempting to automate this suggestion from @kvaps, is that correct? Kudos to him as well for this fantastic guide 🏅

I am curious about how are you planning to support the physical backup restoration? I think you are in a point where you have the physical backup already in a PVC, how are you planning to ship it to a replica?

  • Send the backup through streaming to a replica
  • Mounting the mariabackup PVC

Once the replica has access to the physical backup, how do you plan to actually copy it to /var/lib/mysql:

  • By executing a remote command and follow the @kvaps approach?
  • By introducing and extra initContainer and restart the StatefulSet

Having an initial support for mariabackup would be massive, but in the long term we might want to use it to fix replication scenarios, see: #246 (comment)

Left a couple of suggestions in the PR!

Again, thanks a lot for working on this, you have my full support. Let me know if you need a hand for the implementation! 🙏🏻

Comment thread controllers/mariabackup_controller.go Resolved
Comment thread controllers/mariabackup_controller.go Resolved
Comment thread controllers/mariabackup_controller.go Resolved
Comment thread controllers/mariabackup_controller.go Resolved
Comment thread controllers/mariabackup_controller.go Outdated
if podIP != "" {
// Start mariadb-backup on the primary pod
// TODO: make the backup source configurable primary or replicas
// TODO: add s3 configuration parameters to get backup to s3 directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S3 backup storage is in our roadmap already and something that our community is looking forward to have: #6

If you feel like the PR gets too big feel free to open a new one, or we can take care of it as a separate issue, I leave it up to you. We probably would need to generalize it, not only for physical but also for logical backups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, my initial idea was using the same logic that we have in xtrabackup + xbcloud here that percona has built-in support to get backup directly to s3 and also restore as well. However, it seems there is no such utility like mariadbcloud utility for mariadbbackup. I need to think about this a bit more.

Just as an idea, I could use xtrabackup image in the job pod and it would receive mariabackup stream through socat and upload to bucket with xbcloud like mariadbbackup + xbcloud. As mariadbbackup is ported from xtrabackup hopefully they are compatible.

@mmontes11 mmontes11 Dec 28, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding S3, we have a builtin mechanism based of the mariadb-operator image:

So we don't need to rely on xbcloud

@harunkucuk5

harunkucuk5 commented Nov 15, 2023 •

Copy link
Copy Markdown
Contributor Author

I think this PR is attempting to automate this suggestion from @kvaps, is that correct? Kudos to him as well for this fantastic guide 🏅

I am curious about how are you planning to support the physical backup restoration? I think you are in a point where you have the physical backup already in a PVC, how are you planning to ship it to a replica?

  • Send the backup through streaming to a replica
  • Mounting the mariabackup PVC

Once the replica has access to the physical backup, how do you plan to actually copy it to /var/lib/mysql:

  • By executing a remote command and follow the @kvaps approach?
  • By introducing and extra initContainer and restart the StatefulSet

Hey @mmontes11, thanks for your great review! Regarding your questions, this will be a backup and restore solution for now, so it won't handle scaling up an existing cluster and copying data from master to replica to fix replication for now, but we can implement this as well later on.

So, this PR creates persistent volume if it is not already there and puts backups to that volume. When it comes to restoring I am planning to introduce the init container which will be responsible for the MariaDB backup preparation and copying it to the data folder then it will complete its task. When the actual container starts to run, it will have the data already in the data folder and just start running.

@harunkucuk5
harunkucuk5 marked this pull request as ready for review December 26, 2023 20:58
@harunkucuk5 harunkucuk5 changed the title WIP: Add Support to mariadbbackup Add Support to mariadbbackup Dec 26, 2023
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions Bot added the stale label Apr 19, 2024
@mmontes11 mmontes11 removed the stale label Apr 23, 2024
@pasztorl

Copy link
Copy Markdown

@harunkucuk5 sorry, may I ask an update about this? mariabackup perhaps the most wanted awesome feature

@mmontes11

mmontes11 commented Jul 18, 2024 •

Copy link
Copy Markdown
Member

@pasztorl I encourage you to take a look at this:

Following a similar approach as @harunkucuk5, we are intentding to refactor this and support PITR based on mariabackup + binary logs.

@pasztorl

Copy link
Copy Markdown

@pasztorl I encourage you to take a look at this:

Following a similar approach as @harunkucuk5, we are intentding to refactor this and support PITR based on mariabackup + binary logs.

sounds even better :)

@harunkucuk5

Copy link
Copy Markdown
Contributor Author

@mmontes11 , @pasztorl, sorry that I could not find time to focus on this again.

@mmontes11

Copy link
Copy Markdown
Member

@harunkucuk5 no prob! I will use and refactor these changes to implement PITR and add you as a co-author if that's ok

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity.

@github-actions github-actions Bot added the stale label Sep 30, 2024
@mmontes11 mmontes11 removed the stale label Oct 3, 2024
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity.

@github-actions github-actions Bot added the stale label Dec 14, 2024
@mmontes11 mmontes11 removed the stale label Dec 16, 2024
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity.

@github-actions github-actions Bot added the stale label Feb 15, 2025
@github-actions

Copy link
Copy Markdown

This PR was closed because it has been stalled for 30 days with no activity.

@mmontes11

Copy link
Copy Markdown
Member

This has been supported via this PR: #1266

Thanks for raising the initial changes @harunkucuk5 ! You have been added as co-author.

@mmontes11 mmontes11 closed this Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Physical backups via mariabackup

4 participants