MariaDB Backup and Restore

Revision as of 00:00, 18 September 2020 by Heera Singh Koranga (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MariaDB Backup and Restore

   KB 24154        Last updated on 2020-09-18  

(0 votes)



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`


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 
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

Submitted by: Heera Singh Koranga
Verified Against: ZCS 9.0,8.8 Date Created: 2020-09-17
Article ID: Date Modified: 2020-09-18

Try Zimbra

Try Zimbra Collaboration with a 60-day free trial.
Get it now »

Want to get involved?

You can contribute in the Community, Wiki, Code, or development of Zimlets.
Find out more. »

Looking for a Video?

Visit our YouTube channel to get the latest webinars, technology news, product overviews, and so much more.
Go to the YouTube channel »

Jump to: navigation, search