Difference between revisions of "MariaDB Backup and Restore"

(Created page with " =Overview= ===Backup=== =====Full Backup (Base Backup)===== mkdir -p /opt/db_backup/backup mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=...")
 
Line 1: Line 1:
 +
{{BC|Community Sandbox}}
 +
__FORCETOC__
 +
<div class="col-md-12 ibox-content">
 +
==MariaDB Backup and Restore==
 +
{{KB|{{Unsupported}}|{{ZCS 8.8}}|{{ZCS 9.0}}|}}{{WIP}}
  
=Overview=
+
==Overview==
  
  
  
  
 +
==Backup==
  
===Backup===
+
===Full Backup (Base Backup)===
 
 
=====Full Backup (Base Backup)=====
 
 
  mkdir -p /opt/db_backup/backup
 
  mkdir -p /opt/db_backup/backup
 
  mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`
 
  mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`
  
  
=====Incremental Backup=====
+
===Incremental Backup===
  
 
1st Incremental backup:  
 
1st Incremental backup:  
Line 29: Line 33:
  
  
===Restore===
+
==Restore==
  
=====Prepare Backup for Restore=====
+
====Prepare Backup for Restore====
  
======Prepare Base Backup======
+
=====Prepare Base Backup=====
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup
  
======Apply Incremental Backup to Base Backup======
+
=====Apply Incremental Backup to Base Backup=====
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc1/   
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc1/   
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc2/   
 
  mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc2/   
Line 42: Line 46:
  
  
=====Restore Prepared Backup=====
+
====Restore Prepared Backup====
  
 
1) Stop MariaDB service.  
 
1) Stop MariaDB service.  

Revision as of 15:38, 17 September 2020

MariaDB Backup and Restore

   KB 24154        Last updated on 2020-09-17  




0.00
(0 votes)


Overview

Backup

Full Backup (Base Backup)

mkdir -p /opt/db_backup/backup
mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`


Incremental Backup

1st Incremental backup:

mkdir -p /opt/db_backup/inc1
mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/inc1/ --incremental-basedir=/opt/db_backup/backup/ --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`

2nd Incremental backup:

mkdir -p /opt/db_backup/inc2 
mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/inc2/ --incremental-basedir=/opt/db_backup/inc1/ --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`

3rdIncremental backup:

mkdir -p /opt/db_backup/inc3 
mariabackup --backup -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/inc3/ --incremental-basedir=/opt/db_backup/inc2/ --user=root --password=`zmlocalconfig -s -m nokey mysql_root_password`


Restore

Prepare Backup for Restore

Prepare Base Backup
mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup
Apply Incremental Backup to Base Backup
mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc1/  
mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc2/  
mariabackup --prepare --apply-log-only -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --incremental-dir=/opt/db_backup/inc3/  


Restore Prepared Backup

1) Stop MariaDB service.

mysql.server stop


2) Clear existing datadir (/opt/zimbra/db/data) directory. [ensure that the datadir is empty]

mv /opt/zimbra/db/data /opt/zimbra/db/data.OLD 
mkdir /opt/zimbra/db/data 


3) Restore the prepared backup.

mariabackup --copy-back -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup 
OR
mariabackup --copy-back -S /opt/zimbra/data/tmp/mysql/mysql.sock --target-dir=/opt/db_backup/backup --datadir /opt/zimbra/db/data 


4) Fix the permissions.

chown -R zimbra:zimbra /opt/zimbra/db/data  


5) Start MariaDB service.

mysql.server start
Jump to: navigation, search