Migrar database MySQL/MariaDB usando mydumper/myloader

Esta semana mesmo não conhecendo bem o MariaDB/Mysql, surgiu a necessidade de migrar um banco com 160gb de um servidor antigo para um novo, após algumas horas pesquisando, achei uma solução muito boa para backup lógico usando paralelismo usando o mydumper.

1 – Instalação em Oracle Linux e derivados:

# Oracle Linux 7
yum install https://github.com/maxbube/mydumper/releases/download/v0.11.3/mydumper-0.11.3-1.el7.x86_64.rpm
# Oracle Linux 8 
yum install https://github.com/maxbube/mydumper/releases/download/v0.11.3/mydumper-0.11.3-1.el8.x86_64.rpm
ShellScript

2 – Criar diretório de backup:

mkdir -p /backup/dump/
mkdir -p /backup/log/
ShellScript

3 – Realizando backup de forma simples com 8 threads de paralelismo.

	
nohup mydumper -u 'zabbix' -p 'zabbix' --rows=100000 --compress --triggers --events --routines --threads=8 --verbose=3 --build-empty-files --trx-consistency-only --outputdir=/backup/dump/ 2>/backup/log/dump_backup_log_$(date +%Y%m%d).log &
ShellScript

4 – Geração das permissões e usuários para serem recriados no ambiente novo:

mysql -u'zabbix' -p'zabbix' -B -N -e "SELECT CONCAT('\'', user,'\'@\'', host, '\'') FROM user WHERE user != 'debian-sys-maint' AND user != 'root' AND user != ''" mysql > mysql_all_users.txt
while read line; do mysql -B -N -u'zabbixuser' -p'12itpsolucoes34' -e "SHOW GRANTS FOR $line"; done < mysql_all_users.txt > mysql_all_users_sql.sql
 
sed -i 's/$/;/' mysql_all_users_sql.sql
ShellScript

5 – Importe do dump com 8 threads de paralelismo.

nohup myloader --user='zabbix' --password='zabbix' -B producao --directory=/database/temp/ --threads=8 --compress-protocol --overwrite-tables --verbose=3 -e 2>/database/logs/dump_backup_log_$(date +%Y%m%d).log &

6 – Links:

https://docs.microsoft.com/pt-br/azure/mysql/concepts-migrate-mydumper-myloader
https://www.percona.com/blog/mydumper-0-11-1-is-now-available/ 
https://manpages.debian.org/testing/mydumper/mydumper.1.en.html
 
Official repository:
https://github.com/mydumper/mydumper
https://github.com/maxbube/mydumper/releases
ShellScript

Leave a Reply

Your email address will not be published. Required fields are marked *

search previous next tag category expand menu location phone mail time cart zoom edit close