Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

How to Backup and Restore Contrail Databases in JSON Format

This document shows how to backup and restore the Contrail databases—Cassandra and Zookeeper—in JSON format.

Before You Begin

The backup and restore procedure must be completed for nodes running the same Contrail Networking release. The procedure is used to backup the Contrail Networking databases only; it does not include instructions for backing up orchestration system databases.

CAUTION:

Database backups must be consistent across all systems because the state of the Contrail database is associated with other system databases, such as OpenStack databases. Database changes associated with northbound APIs must be stopped on all the systems before performing any backup operation. For example, you might block the external VIP for northbound APIs at the load balancer level, such as HAproxy.

Simple Database Backup in JSON Format

This procedure provides a simple database backup in JSON format. This procedure is performed using the db_json_exim.py script located in the /usr/lib/python2.7/site-packages/cfgm_common on the controller node.

To perform this database backup:

  1. Log into one of the config nodes. Create the /tmp/db-dump directory on any of the config node hosts.

  2. On the same config node, copy the contrail-api.conf file from the container to the host.

    Ansible Deployer:

    Red Hat Openstack Deployer:

    The Cassandra database instance on any configuration node includes the complete Cassandra database for all configuration nodes in the cluster. Steps 1 and 2, therefore, only need to be performed on one configuration node.

  3. Stop the following docker configuration services on all of the Contrail configuration nodes.

    Ansible Deployer:

    Red Hat Openstack Deployer:

    This step must be performed on each individual config node in the cluster.

  4. Return to the config node where you performed steps 1 and 2.

    List the docker image to find the name or ID of the config api image..

    docker image ls | grep config-api

    Example:

  5. From the same config node, start the config api container pointing the entrypoint.sh script to /bin/bash and mapping /tmp/db-dump from the host to the /tmp directory inside the container. You perform this step to ensure that the API services are not started on the config node.

    Enter the -v /etc/contrail/ssl:/etc/contrail/ssl:ro command option when cassandra_use_ssl is used as api-server configuration parameter to ensure TLS certificates are mounted to the Contrail SSL directory. This mounting ensures that the backup procedure succeeds in environments with endpoints that require TLS authentication.

    The registry_name and container_tag variables must match step 4.

    Example:

    Note:

    In case of RHOSP deployment with RedHat IDM (IPA) (only if CA certificate is different), mount the following file too:

  6. From the docker container created on the config node in Step 5, use the db_json_exim.py script to backup data in JSON format.. The db dump file will be saved in the /tmp/db-dump/ on this config node.

    The Cassandra database instance on any configuration node includes the complete Cassandra database for all configuration nodes in the cluster. You, therefore, only need to perform step 4 through 6 from one of the configuration nodes.

  7. (Optional. Recommended) From the same config node, enter the cat db-dump.json | python -m json.tool | less command to view a more readable version of the file transfer.

  8. From the same config node, exit out of the config api container. This will stop the container.

  9. Start the following configuration services on all of the Contrail configuration nodes.

    Ansible Deployer:

    Red Hat Openstack Deployer:

    This step must be performed on each individual config node.

  10. On each config node, enter the contrail-status command to confirm that services are in the active or running states.

    Note:

    Some command output and output fields are removed for readability. Output shown is from a node hosting config and analytics services.

Examples: Simple Database Backups in JSON Format

These examples illustrate the process for creating a simple database backup in JSON format in both an Ansible deployer environment and a Red Hat Openstack deployer environment.

In each example, a cluster with three config nodes—control_config1, control_config2, and control_config3—is backed up. All tasks that need to be performed on a single config nodes are performed on control-config1. The tasks must be performed in the shown order.

Ansible Deployer Environment:

Red Hat Openstack Deployer Environment:

Restore Database from the Backup in JSON Format

This procedure provides the steps to restore a system using the simple database backup JSON file that was created in Simple Database Backup in JSON Format.

To restore a system from a backup JSON file:

  1. Copy the contrail-api.conf file from the container to the host on any one of the config nodes.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  2. Stop the configuration services on all of the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer—Node hosting Contrail Config containers:

    Red Hat Openstack Deployer—Node hosting Contrail Analytics containers:

  3. Stop the Cassandra service on all the config-db controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  4. Stop the Zookeeper service on all controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  5. Backup the Zookeeper data directory on all the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  6. Delete the Zookeeper data directory contents on all the controllers.

  7. Backup the Cassandra data directory on all the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  8. Delete the Cassandra data directory contents on all controllers.

  9. Start the Zookeeper service on all the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  10. Start the Cassandra service on all the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer:

  11. List docker image to find the name or ID of the config-api image on the config node.

    Example:

  12. Run a new docker container using the name or ID of the config_api image on the same config node.

    Enter the -v /etc/contrail/ssl:/etc/contrail/ssl:ro command option when cassandra_use_ssl is used as api-server configuration parameter to ensure TLS certificates are mounted to the Contrail SSL directory. This mounting ensures that this backup procedure succeeds in environments with endpoints that require TLS authentication.

    Use the registry_name and container_tag from the output of the step 11.

    Example

  13. Restore the data in new running docker on the same config node.

  14. Exit out of the config api container. This will stop the container.

  15. Start config services on all the controllers.

    Ansible Deployer:

    Red Hat Openstack Deployer—Node hosting Contrail Config containers:

    Red Hat Openstack Deployer—Node hosting Contrail Analytics containers:

  16. Enter the contrail-status command on each configuration node and, when applicable, on each analytics node to confirm that services are in the active or running states.

    Note:

    Output shown for a config node. Some command output and output fields are removed for readability.

Example: How to Restore a Database Using the JSON Backup (Ansible Deployer Environment)

This example shows how to restore the databases for three controllers connected to the Contrail Configuration database (config-db). This example assumes a JSON backup file of the databases was previously created using the instructions provided in Simple Database Backup in JSON Format.The network was deployed using Ansible and the three controllers—nodec53, nodec54, and nodec55—have separate IP addresses.

Example: How to Restore a Database Using the JSON Backup (Red Hat Openstack Deployer Environment)

This example shows how to restore the databases from an environment that was deployed using Red Hat Openstack and includes three config nodes—config1, config2, and config3—connected to the Contrail Configuration database (config-db). All steps that need to be done from a single config node are performed from config1.

The environment also contains three analytics nodes—analytics1, analytics2, and analytics3—to provide analytics services.

This example assumes a JSON backup file of the databases was previously created using the instructions provided in Simple Database Backup in JSON Format.