We perform data backups everyday at 2:00 am and restore its data on the other database to ensure that data backup and restore is being done perfectly. We perform mysql backup and restore it in Devops server and expose its metric to the grafana about the back up and restore details. So that we can make alerting on it. All this operations are being done everyday with the help of jenkins pipelines.
Grafana > Dashboards > rupid-prod-mysql-monitoring > MySql backup
0: MySQL backup successful and Database is consistent
1: MySQL backup is inconsistent
2: Backup creation failed on MySQL server
3: Failed to Copy backup to Backup server
4: Importing backup failed on Backup server
Incremental backups work because each InnoDB page contains a log sequence number, or LSN. The LSN is the system version number for the entire database. Each page’s LSN shows how recently it was changed.
The algorithm reads the data pages and checks the page LSN of the last incremental Backup and take the data from last LSN to present LSN.
We can see these LSN details in .xtrabackup_checkpoints file
Sample contents of .xtrabackup_checkpoints file of incremental backup folder
backup_type = incremental
from_lsn = 1626007`
to_lsn = 4124244
last_lsn = 4124244
compact = 0
recover_binlog_info = 1
xtrabackup --backup --target-dir=${backupDir}/inc_${currentDate} --incremental-basedir=${backupDir}/inc_${lastDate} -u ${db.user} -p${db.password}
The inc_${lastDate}/ contains the incremental backup files one of those is, .xtrabackup_checkpoints file. The xtrabackup checks the last_lsn value, the xtrabackup checks that last lsn value before taking incremental backup and take the incremental backup from that last Log Sequence Number.
xtrabackup --prepare --apply-log-only --target-dir=${remoteBackupDir}/base_${lastDate} --incremental-dir=${remoteBackupDir}/inc_${currentDate}/
In the process of preparing the incemental backup, it checks the last lsn of last prepared full backup(base data which have already prepared, if not it is the base directory) and prepares the data and merge the differences between the founded log lsn of previous prepared backup and present taken backup.
The next step is to replace all data directory files of mysql-server with the prepared backup folder i.e folder which got incremental changes are merged.
/data/backups/mysql/rupid-demo/inc : Contains all incremental backup related files
inc/compressed : Contains all full backup archives with the file names base_dd-mm-yy.tar.gz
inc/inc-dd_mm_yy : : Contains all incremental files with specified dates.
Today: 17-05-2024
We configured the backup metric in a way that it can send email alerts when backup value is other than 0. So that we can alert on the issue and fix it as soon as possible.