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=...")
(No difference)

Revision as of 15:28, 17 September 2020

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