PDB-BACKUP Versão 1.0.0
O PDB-BACKUP é um conjunto de scripts para gerenciar a realização de backups através das ferramentas Percona XtraBackup, MariaBackup, MySQlBackup(MEB) e MySQLDump, de backups do tipo FULL e INCREMENTAL inclusive para o MySQLDump, mas sobre como funciona esse processo e os riscos envolvidos referente a integridade do backup incremental através do MySQLDump falaremos mais abaixo.
Para ver todas as opções de execução basta acessar o help do script.
pdb-backup --help
PDB Backup Version 1.0.0
Usage: pdb-backup {full|incremental}
The pdb-backup is not a backup tool, but a set of scripts that facilitates and controls the generation of full and incremental MySQL backups through mysqldump, Percona Xtrabackup, MariaDB mariabackup or MySQL Enterprise Backup.
Examples of backup scheduling (crontab):
0 0 * * * pdb-backup full >/dev/null 2>&1
0 6,12,18 * * * pdb-backup incremental >/dev/null 2>&1
To change the backup settings:
Just run the pdb-tools-config command
OR
Edit the /etc/pdbtools.cnf configuration file
The pdb-backup is part of a set of tools developed by PerformanceDB, see the other tools on our website.
www.performancedb.com
pdbtools@performancedb.com
Como configurar o PDB TOOLS para realizar backups
1. Acesso o pdb-tools-config
pdb-tools-config
****************************
* Setting up the PDB-TOOLS *
****************************
PDB Tools is a set of scripts developed by PerformanceDB (www.performancedb.com). All PDB Tools scripts are free and have been developed from DBA to DBA.
In this program you will be able to configure some scripts that require configuration, but all the settings can be changed by editing the configuration file /etc/pdbtools.cnf.
*****************************
Select the one you want to configure
[1] MySQL Access and Path Information.
- Some scripts require you to configure user and and MySQL access
- Path of MySQL Cli and MySQL Daemon
- MySQL socket and port
[2] MySQL Service Checker
- Send notifications
- Notifications can be sent by:
- mail service on localhost server
- sparkpost(www.sparkpost.com)
- script developed by you
[3] MySQL Replication Checker
- Send notifications
- Notifications can be sent by:
- mail service on localhost server
- sparkpost(www.sparkpost.com)
- script developed by you
[4] Backup
- PDB Tools can perform backups through the following tools:
- mysqldump(full and incremental)
- Percona Xtrabackup(full and incremental)
- MariaDB mariabackup(full and incremental)
- MySQL Enterprise Backup(full and incremental)
- Send notifications when success or error in backup
- Notifications can be sent by:
- mail service on localhost server
- sparkpost(www.sparkpost.com)
- script developed by you
[0] Exit
Which of option above do you want to configure?
2. Selecione a opção 4([4] Backup) e informe qual o programa que deseja utilizar para realizar os backups. Veja que o script já verifica quais estão instalados e só vai permitir configurar os que já estiverem instalados
*****************************
* Setting up the PDB-BACKUP *
*****************************
The PDB-BACKUP is not a backup tool, but a set of scripts that facilitates and controls the generation of full and incremental MySQL backups through mysqldump, Percona Xtrabackup, MariaDB mariabackup or MySQL Enterprise Backup.
Some settings will be necessary for the correct operation of the PDB-BACKUP, as well as the backup tool used, but all the settings requested here can be changed manually by editing the PDB Tools configuration file /etc/pdbtools.cnf.
*****************************
The PDB Scripts is not yet configured to perform backups, but that s pretty simple, come on!
[1] mysqldump(installed)
[2] Percona Xtrabackup(not installed)
[3] MariaDB mariabackup(installed)
[4] MySQL Enterprise Backup(not installed)
Which of option above programs will be used to perform the backups?
3. Independente do programa de backup escolhido, o próximo passo é criar a tabela que irá controlar os backups basta executar o script sql indicado na configuração. será criado o database performancedb e a tabela backups
Verifying that the selected program is installed...
Done! I have already verified that 'mariabackup' is installed, we will continue the configuration of PDB Backup.
Now it is necessary to create the table that will control the execution of the backups, so execute this scripts in your database: /opt/pdbtools/share/pdb-backup-create-table.sql
The script has already run, can we continue? [Y]
4. Informe o path onde os backups serão salvos
Now enter the path that backups should be saved.
* Important: do not put the / at the end
e.g. /backup
Enter the backup path here:
5. Informe se deseja compactar o backup ao final do backup. Caso deseje o script de configuração vai listar os métodos de compactação disponíveis para o seu servidor
Do you want the backup to be compressed?: [Y/N] y
Choose the form of compression, below I will show a list with the options available on your server.
- tar
Enter the name of the compression you want:
6. Informe se deseja disparar notificação ao termino ou em caso de erro do backup
When the backup completes, an email can be sent with the backup log.
The email can be sent through the server itself using the 'mail' program OR through sparkpost(www.sparkpost.com) OR Script developed by you
Do you want to enable email sending?: [Y/N] y
How do you want to send the e-mail?
- mail(Make sure this server is set up correctly to send email)
- sparkpost(You will need to enter the API Key)
- Script(Script developed by you)
Enter 'mail' or 'sparkpost' or 'script':
Na sequência será solicitadas uma série de informações para que seja configurado o disparo da notificação.
Ao final desse passo o PDB-BACKUP está pronto para ser executado, porém existem mais configurações que podem ser feitas, mas devem ser feitas diretamente no arquivo de configuração do PDB TOOLS /etc/pdbtools.cnf
Uma das configurações possíveis é informar um script para ser executado ao final do backup, que pode por exemplo enviar o backup para um storage ou serviço de armazenamento na nuvem.
vim /etc/pdbtools.cnf
.
.
.
#Script to run after the end of backup
#Enter the full script path
# e.g. sh /home/user/send_to_s3.sh
# The path of the file generated by the backup will be sent as parameter $1
_pdbtools_post_backup_script="sh /backup/pdb-backup/syncs3.sh"
.
.
.
Configurações exclusivas para o MariaBackup
vim /etc/pdbtools.cnf
.
.
.
#
#[maribackup]
#
#In this session you can make some changes that affect mariabackup
#The names of the variables below refer to the same name as the mariabackup options, here you will see only the prefix _pdbtools_mariabackup_ in front of the name, but the rest is the same.
#_pdbtools_mariabackup_compress possible values:
# 0 = NO
# 1 = YES
_pdbtools_mariabackup_compress=1
#_pdbtools_mariabackup_slave_info possible values:
# 0 = NO
# 1 = YES
_pdbtools_mariabackup_slave_info=1
_pdbtools_mariabackup_parallel=6
_pdbtools_mariabackup_compress_threads=4
#_pdbtools_maribackup_extra_options
# Here you can inform any option accepted by maribackup.
_pdbtools_maribackup_extra_options=""
.
.
.
Configurações exclusivas para o Percona XtraBackup
vim /etc/pdbtools.conf
.
.
.
#
#[xtrabackup]
#
#In this session you can make some changes that affect Percona Xtrabackup
#The names of the variables below refer to the same name as the Percona Xtrabackup options, here you will see only the prefix _pdbtools_xtrabackup_ in front of the name, but the rest is the same.
#_pdbtools_xtrabackup_compress possible values:
# 0 = NO
# 1 = YES
_pdbtools_xtrabackup_compress=1
#_pdbtools_xtrabackup_slave_info possible values:
# 0 = NO
# 1 = YES
_pdbtools_xtrabackup_slave_info=1
_pdbtools_xtrabackup_parallel=6
_pdbtools_xtrabackup_compress_threads=4
#_pdbtools_xtrabackup_extra_options
# Here you can inform any option accepted by xtrabackup.
_pdbtools_xtrabackup_extra_options=""
.
.
.
Configurações exclusivas para o MySQLBackup(MEB)
vim /etc/pdbtools.cnf
.
.
.
#
#[mysqlbackup]
#
#In this session you can make some changes that affect MySQL Enterprise Backup
#The names of the variables below refer to the same name as the mysqlbackup options, here you will see only the prefix _pdbtools_mysqlbackup_ in front of the name, but the rest is the same.
#_pdbtools_mysqlbackup_compress possible values:
# 0 = NO
# 1 = YES
_pdbtools_mysqlbackup_compress=1
#_pdbtools_mysqlbackup_slave_info possible values:
# 0 = NO
# 1 = YES
_pdbtools_mysqlbackup_slave_info=1
#_pdbtools_mysqlbackup_extra_options
# Here you can inform any option accepted by mysqlbackup.
_pdbtools_mysqlbackup_extra_options=""
.
.
.
Configurações exclusivas para o MySQLDump
vim /etc/pdbtools.cnf
.
.
.
#
#[mysqldump]
#
#path to mysqldump bin
_pdbtools_mysqldump_bin=mysqldump
#path to mysqlbinlog bin
_pdbtools_mysqlbinlog_bin=mysqlbinlog
#Logbin path
# * Important: do not put the / at the end
# e.g. /var/lib/mysql
_pdbtools_logbin_path=
#_pdbtools_mysqldump_dump_slave possible values:
# 0 = NO
# 1 = YES
_pdbtools_mysqldump_dump_slave=1
#_pdbtools_mysqldump_extra_options
# Here you can inform any option accepted by mysqldump.
# * Important: Never leave this option empty
# At a minimum with --all-databases or --databases <database name> is required
_pdbtools_mysqldump_extra_options="--all-databases"
.
.
.
Pronto, agora é só realizar os backups.
Para automatizar os backups basta adicionar a execução do PDB-BACKUP em um agendados de tarefas como o crontab ou supervisor
Cuidados com o Backup Incremental com o MySQLDump
Primeiramente o MySQLDump não realiza backups e sim gera dump que é uma exportação dos dados para arquivo texto, mas para facilitar as nomenclaturas estamos tratando como backup.
Segundo, o MySQLDump não realiza backup incremental apenas full, porém o PDB BACKUP realiza essa operação exportando os dados do log binário, por isso o log binário precisa estar ativado. No momento do backup full(com o mysqldump) o PDB BACKUP salva a posição do log binário que será o ponto de inicio do backup incremental, e quando um backup incremental for realizado o PDB BACKUP vai exportar os dados dos log binários gerados após o backup full, iniciando da posição armazenada no backup full com o programa mysqlbinlog. Esse não é um procedimento 100% seguro, pois se comandos forem executados de forma que não sejam gravados no log binário, você terá um backup não integro. O PDB BACKUP apenas possibilita que isso seja feito, mas a segurança para que não existam essas inconsistências no backup é sua.