Skip to main content
Version: 3.0

Back up RabbitMQ on Kubernetes

Applicable to both Classic and Federated modes

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 recommends that RabbitMQ must be stopped in order to back up messages properly.

Installation

Prerequisites

note
  • 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 run both before and after the backup operation runs:

Create a pre-exec backup rule for RabbitMQ

Set up a rule with two actions. The first action is to export_definitions to a location within /var/lib/rabbitmq so that the version of definitions for that node is available with any given restore point.

The second action is to run stop_app since it is the best practice to make sure RabbitMQ is not running during the snapshot.

  1. From the home page, navigate to Settings > Rules > Add New.

  2. 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: This field is mandatory if you're using mTLS with the Linkerd service mesh, provide the container name. Otherwise, leave this field blank.

    • 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 rule that runs start_app. This brings each RabbitMQ app back online after the data snapshot takes place. This ensures the backup is application consistent.

  1. From the home page, navigate to Settings >Rules > Add New.

  2. 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: This field is mandatory if you're using mTLS with the Linkerd service mesh, provide the container name. Otherwise, leave this field blank.

  • 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:

  • After you populate all the fields of the Create Backup window, click Create.