Run the following command on the root node to create a full backup:
xtrabackup --backup --target-dir=/data/backups/
Copy the backup files from the root node to the backup node using scp
:
scp -i /home/devopsadmin/.ssh/id_rsa -P <port_number> -r /data/backups/ devopsadmin@<backup-host>:/data/backups/
Replace the placeholders:
<port_number>
with the SSH port (e.g., 22
).<backup-host>
with the IP address or hostname of the backup node.Once the backup files are transferred, prepare the full backup on the backup node to make it ready for restoration:
xtrabackup --prepare --target-dir=/data/backups/
Sync the prepared backup files to the MySQL data directory on the backup node:
rsync -avrP /data/backups/ <mysql_datadir>
Replace <mysql_datadir>
with the path to the MySQL data directory (e.g., /var/lib/mysql/
).
On the backup node, prepare the incremental backup to apply the changes to the base backup:
xtrabackup --prepare --apply-log-only --target-dir=/data/backups/base_<last_date>
This command applies the incremental changes to the base backup directory.
This pipeline automates the process of taking MySQL incremental backups, copying them to a remote server, preparing the backups, and restoring them. It uses Jenkins and integrates commands such as xtrabackup
for backup creation, tar
for compression, and rsync
for restoring the files.
Purpose: Creates an incremental backup for MySQL using xtrabackup
based on the previous day’s backup.
Prerequisites:
/data/backups/mysql/pssb/inc/inc_<lastDate>
).Steps:
/data/backups/mysql/pssb/inc/inc_<currentDate>
).xtrabackup
command to take an incremental backup..tar.gz
file.Error Codes:
2
: Previous backup directory not found.3
: Incremental backup creation failed.Example Command:
sudo /usr/bin/xtrabackup --backup \
--target-dir=/data/backups/mysql/pssb/inc/inc_16-12-24 \
--incremental-basedir=/data/backups/mysql/pssb/inc/inc_15-12-24 \
-u root -pGr@mSev@k@123
Purpose: Copies the compressed backup file to a remote backup server.
Prerequisites:
/home/devopsadmin/.ssh/id_rsa
).Steps:
scp
with the specified port and identity file.Error Codes: N/A
Example Command:
scp -i /home/devopsadmin/.ssh/id_rsa -P 59222 \
/data/backups/mysql/pssb/inc/compressed/inc_16-12-24.tar.gz \
devopsadmin@103.210.73.207:/data/backups/mysql/compressed/inc_16-12-24.tar.gz
Purpose: Prepares the incremental backup for restoration by applying logs.
Prerequisites:
Steps:
xtrabackup
to prepare the incremental backup and apply logs to the base directory.Error Codes:
4
: Backup file not found on the remote server.5
: Preparing the incremental backup failed.Example Command:
sudo tar -xzvf /data/backups/mysql/compressed/inc_16-12-24.tar.gz -C /data/backups/mysql/inc_16-12-24
sudo xtrabackup --prepare --apply-log-only \
--target-dir=/data/backups/mysql/base_15-12-24 \
--incremental-dir=/data/backups/mysql/inc_16-12-24
Purpose: Restores the prepared backup to the MySQL data directory.
Prerequisites:
Steps:
rsync
to copy the backup data to the MySQL data directory.Error Codes:
6
: Failed to replace files during restoration.Example Command:
sudo rsync -avrP /data/backups/mysql/base_15-12-24/ /data/db/pxc/mysql/
sudo chmod 750 -R /data/db/pxc/mysql/
sudo chown -R mysql:mysql /data/db/pxc/mysql/
sudo systemctl start mysql@bootstrap
This pipeline includes custom error messages mapped to the following status codes:
Status Code | Description |
---|---|
0 |
MySQL incremental backup successful, database is consistent |
1 |
MySQL backup is inconsistent |
2 |
Base directory files not found or cannot get sequence no |
3 |
Backup creation failed on MySQL server |
4 |
Failed to copy backup to backup server |
5 |
Backup preparation failed |
6 |
Importing backup failed on the backup server |
After restoring the incrementally prepared backup, rename the base folder to the current date. This ensures it can be used as the base for the next incremental backup:
mv /data/backups/base_<last_date> /data/backups/base_<current_date>
<last_date>
with the previous base folder’s date.<current_date>
with the current date.Note: Renaming the folder is essential to use it as the base directory for the next incremental backup.
To verify consistency between the demo node and the backup node, use the genReport.sh
script. This script compares row counts in both databases.
bash genReport.sh -u root -p Gr@mSev@k@123 -d psdb_sb
-u
: MySQL username (e.g., root
).-p
: MySQL password (e.g., Gr@mSev@k@123
).-d
: Database name (e.g., psdb_sb
).This script will generate a report of row counts, ensuring that the demo node and backup node data are consistent.
The backup process failed on February 07, 2025, and as of February 10, 2025, recovery needs to be initiated
cd /data/backups/mysql/demo/inc/base_07-02-25
xtrabackup_checkpoints
file to retrieve the LSN:
cat xtrabackup_checkpoints
root@pssb1bvm006:/data/backups/mysql# cat base_07-02-25/xtrabackup_checkpoints
backup_type = log-applied
from_lsn = 0
to_lsn = 8239522152
last_lsn = 8239522152
flushed_lsn = 8239492299
redo_memory = 0
redo_frames = 0
to_lsn
value. This will be used to determine the correct incremental backup.devopsadmin@pssb1abm003:/data/backups/mysql/pssb/inc$ sudo grep -iR "to_lsn = 8239522152" .
./inc_07-02-25/xtrabackup_info:innodb_to_lsn = 8239522152
./inc_07-02-25/xtrabackup_checkpoints:to_lsn = 8239522152
mv /data/backups/mysql/demo/inc/inc_07-01-25 /data/backups/mysql/demo/inc/inc_prev_YYYYMMDD
mv inc_07-02-25/ inc_09-02-25
Replace YYYYMMDD
with the actual date.mv /data/backups/mysql/demo/inc/base_07-02-25 /data/backups/mysql/demo/inc/base_prev_YYYYMMDD
mv base_07-02-25/ base_09-02-25/
Replace YYYYMMDD
with the actual date.This Jenkins pipeline automates the process of backing up, copying, restoring, and verifying data from a Scylla database. The pipeline includes the following stages: Get and Restore Schema, Take Backup, Copy Backup, Restore Backup, Count Rows in Demo and Count Rows in Demo. Below is an explanation of how each stage works, with an example for each.
The pipeline is structured to perform the following tasks:
Purpose: This stage generates the schema from the database and restores it.
Steps:
genSchema.sh
script is executed to generate the schema file (schema.cql
).devopsadmin
user has access.restoreSchema
is true), the generated schema is copied to the remote server and restored using cqlsh
.Example:
psds_sb
keyspace is generated and then restored on the remote server using the scp
command.Purpose: This stage takes a snapshot of the keyspace and compresses it into a tarball.
Steps:
nodetool flush
command is used to ensure that all memory data is pushed to disk.nodetool snapshot
.psds_sb
keyspace are identified and their data directories are located..tar.gz
file.Example:
psds_sb
keyspace is created and compressed into a file named tableName_snapshot.tar.gz
.Purpose: This stage copies the backup files to a remote server for storage.
Steps:
scylla_fullbkp_${currentDate}.tar.gz
) is copied to the remote server using scp
.Example:
pssb1bvm006
server for storage.Purpose: This stage restores the backup data to the Scylla instance.
Steps:
Example:
scylla_fullbkp_${currentDate}.tar.gz
file is extracted, and the corresponding table snapshots are restored on the remote server.Purpose: This stage counts the rows in a demo keyspace and generates a report.
Steps:
genReport.sh
script is executed to count the rows in the demo keyspace.Example:
psds_sb
keyspace on the demo server.Purpose: This stage counts the rows in a demo keyspace and generates a report.
Steps:
genReport.sh
script is executed to count the rows in the demo keyspace.Example:
psds_sb
keyspace on the demo server.The pipeline includes error handling to manage various failure scenarios. The status codes and their corresponding error messages are as follows:
Status Code | Message |
---|---|
0 | Scylla Full Backup backup successful and Database is consistent |
1 | Scylla backup is inconsistent |
2 | Error Flushing the keyspace scylla might not in running state |
3 | Error while Creation of Snapshot scylla on Prod server might not running |
4 | Failed to Copy backup to Backup server |
5 | Backup Restoration failed |
6 | Error finding the table in Backup server, schema may be changed |
Each stage checks for potential issues and updates the statusCode
variable accordingly. If an error occurs, the pipeline halts and the corresponding error message is displayed.
psds_sb
keyspace is taken and compressed into a tarball.