MariaDB 10.2 Xtrabackup Error: WSREP_SST_OPT_PORT: Unbound Variable - Explained
- MariaDB 10.2 Xtrabackup: This specifies the MariaDB version (10.2) and the tool being used for backup (Xtrabackup).
- /usr/bin/wsrep_sst_xtrabackup-v2: This is the path to the script used for performing State Snapshot Transfer (SST) with Xtrabackup.
- WSREP_SST_OPT_PORT: unbound variable: This is the core of the error message. It indicates that the script is trying to use an environment variable named
WSREP_SST_OPT_PORT
but this variable is not set.
What is WSREP_SST_OPT_PORT?
This environment variable likely controls a port number used during the MariaDB cluster State Snapshot Transfer (SST) process with Xtrabackup. SST allows a new node to join a Galera cluster by transferring the current state of the cluster from an existing member.
How to Fix the Error
To fix this error, you need to set the WSREP_SST_OPT_PORT
environment variable before running the wsrep_sst_xtrabackup-v2
script. You can achieve this in two ways:
-
Setting in Shell Environment:
Open a terminal and run the following command to set the variable temporarily for your current shell session:
export WSREP_SST_OPT_PORT=PORT_NUMBER
Replace
PORT_NUMBER
with the actual port you want to use for the SST process. -
Setting in Script:
Additional Information:
- It's important to choose a port number that is not being used by other applications on your system to avoid conflicts.
While not ideal for Galera clusters due to potential inconsistencies, here's an example of using xtrabackup
for a full backup:
xtrabackup --backup --target-dir=/backup/mariadb_full_backup
This command creates a full backup of your MariaDB data directory in the /backup/mariadb_full_backup
directory.
Using mariabackup (Recommended for MariaDB 10.2 and Later):
MariaDB introduced mariabackup
as a more integrated and recommended alternative to Percona Xtrabackup. Here's an example:
mariabackup --backup --target-dir=/backup/mariadb_full_backup
This command functions similarly to the xtrabackup
example but is the preferred method for MariaDB backups.
Galera Cluster SST with xtrabackup (Use with Caution):
Important Note: Due to potential inconsistencies, this approach should be used with caution and only if mariabackup
is not an option. Refer to MariaDB documentation for supported methods for Galera cluster backups.
Here's a cautionary example using xtrabackup
for a Galera cluster SST (State Snapshot Transfer):
# Stop slave threads (Optional, might be needed depending on your setup)
mysql -e 'STOP SLAVE;'
# Prepare for backup (Replace <source_server>, <destination_server> with actual hostnames)
xtrabackup --prepare --host=<source_server>
# Perform backup on source server
xtrabackup --backup --host=<source_server> --target-dir=/tmp/galera_sst_backup
# SCP backup directory to destination server (Replace user@destination_server with actual details)
scp -r /tmp/galera_sst_backup user@<destination_server>:/tmp/
# On destination server, prepare for SST using received backup
xtrabackup --prepare --apply-log --host=<destination_server> --xtrabackup-dir=/tmp/galera_sst_backup
# Start slave threads (Optional)
mysql -e 'START SLAVE;'
- This method creates a text dump of your database schema and data.
- It's a good choice for smaller databases or for backing up specific databases/tables.
- However, restoring a complete database from a logical backup can be time-consuming.
Example:
mysqldump -u username -p database_name > /backup/mariadb_logical_backup.sql
Native MariaDB Backup with mariadb-backup (Recommended):
- This is the preferred method for MariaDB backups, introduced in MariaDB 10.1.
- It offers functionalities similar to Percona Xtrabackup but is specifically designed for MariaDB and handles features like compression and encryption.
Continuous Archiving with Tools like Myreplication:
- This approach focuses on replicating ongoing database changes to a separate server for disaster recovery purposes.
- Tools like Myreplication continuously stream database updates to a slave server, ensuring near real-time backups.
- This method requires additional setup and management but offers a more robust solution for continuous data protection.
Choosing the Right Method:
The best method depends on your specific needs:
- For quick backups of smaller databases,
mysqldump
might suffice. - For consistent, reliable backups with MariaDB-specific features,
mariadb-backup
is recommended. - For continuous data protection and disaster recovery, consider tools like Myreplication.
Additional Tips:
- Regardless of the method, automate your backups to ensure regular and consistent data protection.
- Store backups on a separate server or cloud storage for added security.
- Regularly test your backups to ensure successful restores when needed.
mariadb