Backup RabbitMQ on Kubernetes
You can use the instructions on this page to create pre and post backup rules with Portworx Backup, which take application-consistent backups for RabbitMQ on Kubernetes in production.
Every RabbitMQ node uses a number of files and directories to load configuration, metadata, and log files. The directory setting which configures RabbitMQ’s node database directory is called RABBITMQ_MNESIA_BASE
. The databases in this directory hold RabbitMQ messages. This directory can be overridden and therefore configured differently. Most often it is located at /var/lib/rabbitmq/mnesia
.
Make sure /var/lib/rabbitmq
is mounted to a volume within the pod specification.
Topology definitions and messages are the most valuable types of data in RabbitMQ. RabbitMQ suggests exporting definitions. RabbitMQ also suggests RabbitMQ must be stopped in order to back up messages properly.
Installation
Prerequisites
- RabbitMQ pods must have a label for this to work properly.
app=rabbitmq-ha
is used in this example. - RabbitMQ queues must be durable and messages must be persistent.
Create rules for RabbitMQ
Create rules for RabbitMQ that will run both before and after the backup operation runs:
Create a pre-exec backup rule for RabbitMQ
You will set up a rule with two actions. The first action will be to export_definitions
to a location within /var/lib/rabbitmq
so that the version of definitions for that node will be available with any given restore point.
The second action will be to run stop_app
since it is the best practice to make sure RabbitMQ is not running during the snapshot.
-
From the home page, navigate to Settings > Rules > Add New.
-
In the Add Rule window, provide the following details:
-
Rule name: add a name for your backup rule
-
Pod Selector: add the following app label
app=rabbitmq-ha
-
Container: ignore this field
-
Action: add the following action
rabbitmqctl export_definitions /var/lib/rabbitmq/definitions.file.json
- Add a second action to the same rule:
rabbitmqctl stop_app
-
Create a post-exec backup rule for RabbitMQ
Next, create a post-exec that runs start_app
. This will bring each RabbitMQ app back online after the data snapshot takes place. This ensures the backup is application consistent.
-
From the home page, navigate to Settings >Rules > Add New.
-
In the Add Rule window, provide the following details:
-
Rule name: add a name for your backup rule
-
Pod Selector: add the following app label
app=postgres
-
Container: ignore this field
-
Action: add the following action
rabbitmqctl start_app
Use the rules during backup of RabbitMQ
During the backup creation process, select the rules in the pre-exec and post-exec dropdown lists:
- Once you have populated all the fields of Create Backup window, click Create.
Demo
Watch this short demo of the above information.