{"id":7787,"date":"2019-01-07T16:29:35","date_gmt":"2019-01-07T08:29:35","guid":{"rendered":"http:\/\/rmohan.com\/?p=7787"},"modified":"2019-01-07T16:29:37","modified_gmt":"2019-01-07T08:29:37","slug":"how-to-backup-and-restore-rabbitmq-data-configurations","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7787","title":{"rendered":"How to Backup and Restore RabbitMQ Data &#038; Configurations"},"content":{"rendered":"\n<p>In this post, I\u2019ll like us to look at how to perform a backup for RabbitMQ configurations and data. This will also include information on restoring a RabbitMQ backup into a new deployment.<\/p>\n\n\n\n<p>Get Cluster Status<\/p>\n\n\n\n<p>$ rabbitmqctl cluster_status<br>\nCluster status of node rabbit@computingforgeeks-centos7 \u2026<br>\n[{nodes,[{disc,[&#8216;rabbit@computingforgeeks-centos7&#8217;]}]},<br>\n{running_nodes,[&#8216;rabbit@computingforgeeks-centos7&#8217;]},<br>\n{cluster_name,&lt;&lt;&#8220;rabbit@computingforgeeks-centos7&#8221;&gt;&gt;},<br>\n{partitions,[]},<br>\n{alarms,[{&#8216;rabbit@computingforgeeks-centos7&#8217;,[]}]}]<br>\nHow to Backup RabbitMQ Configurations<br>\nPlease note this backup doesn\u2019t include Messages since they are stored in a separate message store. It will only backup RabbitMQ users, vhosts, queues, exchanges, and bindings. The backup file is a JSON representation of RabbitMQ metadata. We will do a backup using rabbitmqadmincommand line tool.<\/p>\n\n\n\n<p>The management plugin ships with a command line tool rabbitmqadmin. You need to enable the management plugin:<\/p>\n\n\n\n<p>rabbitmq-plugins enable rabbitmq_management<br>\nThis plugin is used to perform some of the same actions as the Web-based UI, and which may be more convenient for automation tasks.<\/p>\n\n\n\n<p>Download rabbitmqadmin<br>\nOnce you enable the management plugin, download rabbitmqadmin  Python command line tool that interacts with the HTTP API. It can be downloaded from any RabbitMQ node that has the management plugin enabled at<\/p>\n\n\n\n<p>http:\/\/{node-hostname}:15672\/cli\/<br>\nOnce downloaded, make the file executable and move it to \/usr\/local\/bin directory:<\/p>\n\n\n\n<p>chmod +x rabbitmqadmin<br>\nsudo mv rabbitmqadmin \/usr\/local\/bin<br>\nTo backup RabbitMQ configurations, use the command:<\/p>\n\n\n\n<p>rabbitmqadmin export <br>\nExample:<\/p>\n\n\n\n<p>$ rabbitmqadmin export rabbitmq-backup-config.json<br>\nExported definitions for localhost to &#8220;rabbitmq-backup-config.json&#8221;<br>\nThe export will be written to filerabbitmq-backup-config.json.<\/p>\n\n\n\n<p>How to Restore RabbitMQ Configurations backup<br>\nIf you ever want to restore your RabbitMQ configurations from a backup, use the command:<\/p>\n\n\n\n<p>rabbitmqadmin import <br>\nExample<\/p>\n\n\n\n<p>$ rabbitmqadmin import rabbitmq-backup.json <br>\nImported definitions for localhost from &#8220;rabbitmq-backup.json&#8221;<br>\nHow to Backup RabbitMQ Data<br>\nRabbitMQ Definitions and Messages are stored in an internal database located in the node\u2019s data directory. To get the directory path, run the following command against a running RabbitMQ node:<\/p>\n\n\n\n<p>rabbitmqctl eval &#8216;rabbit_mnesia:dir().&#8217;<br>\nSample output:<\/p>\n\n\n\n<p>&#8220;\/var\/lib\/rabbitmq\/mnesia\/rabbit@computingforgeeks-server1&#8221;<br>\nThis directory contains many files:<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">ls \/var\/lib\/rabbitmq\/mnesia\/rabbit@computingforgeeks-centos7<\/h1>\n\n\n\n<p>cluster_nodes.config  nodes_running_at_shutdown    rabbit_durable_route.DCD       rabbit_user.DCD             schema.DAT<br>\nDECISION_TAB.LOG      rabbit_durable_exchange.DCD  rabbit_runtime_parameters.DCD  rabbit_user_permission.DCD  schema_version<br>\nLATEST.LOG            rabbit_durable_exchange.DCL  rabbit_serial                  rabbit_vhost.DCD<br>\nmsg_stores            rabbit_durable_queue.DCD     rabbit_topic_permission.DCD    rabbit_vhost.DCL<br>\nIn RabbitMQ versions starting with 3.7.0 all messages data is combined in the msg_stores\/vhosts directory and stored in a subdirectory per vhost. Each vhost directory is named with a hash and contains a .vhost file with the vhost name, so a specific vhost\u2019s message set can be backed up separately.<\/p>\n\n\n\n<p>To do RabbitMQ definitions and messages data backup, copy or archive this directory and its contents. But first, you need to stop RabbitMQ service<\/p>\n\n\n\n<p>sudo systemctl stop rabbitmq-server.service<br>\nThe example below will create an archive:<\/p>\n\n\n\n<p>tar cvf rabbitmq-backup.tgz \/var\/lib\/rabbitmq\/mnesia\/rabbit@computingforgeeks-centos7<br>\nHow to Restore RabbitMQ Data<br>\nTo restore from Backup, extract the files from backup to the data directory.<\/p>\n\n\n\n<p>Internal node database stores node\u2019s name in certain records. Should node name change, the database must first be updated to reflect the change using the following rabbitmqctl command:<\/p>\n\n\n\n<p>rabbitmqctl rename_cluster_node  <br>\nWhen a new node starts with a backed up directory and a matching node name, it should perform the upgrade steps as needed and proceed to boot.<\/p>\n","protected":false},"excerpt":{"rendered":"\n<p>In this post, I\u2019ll like us to look at how to perform a backup for RabbitMQ configurations and data. This will also include information on restoring a RabbitMQ backup into a new deployment.<\/p>\n<p>Get Cluster Status<\/p>\n<p>$ rabbitmqctl cluster_status Cluster status of node rabbit@computingforgeeks-centos7 \u2026 [{nodes,[{disc,[&#8216;rabbit@computingforgeeks-centos7&#8217;]}]}, {running_nodes,[&#8216;rabbit@computingforgeeks-centos7&#8217;]}, {cluster_name,&lt;&lt;&#8220;rabbit@computingforgeeks-centos7&#8221;&gt;&gt;}, {partitions,[]}, {alarms,[{&#8216;rabbit@computingforgeeks-centos7&#8217;,[]}]}] How to Backup RabbitMQ [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7787"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7787"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7787\/revisions"}],"predecessor-version":[{"id":7788,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7787\/revisions\/7788"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}