Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Backing up Contrail Databases in JSON Format

This document shows how to take backup of Contrail databases (Cassandra and Zookeeper) in JSON format.

Preliminary Caution

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

Perform a simple backup (database dump). Use db_json_exim.py, located at /usr/lib/python2.7/site-packages/cfgm_common on controller node.

Note:

The controller node for non-containerized Contrail is a virtual machine (VM).

The controller node for containerized Contrail is a controller container.

  1. Run the following command on any one of the controller nodes to go to config_api_1 container.

    docker exec -it config_api_1 bash

  2. Backup data with db_json_exim in JSON format.

    cd /usr/lib/python2.7/site-packages/cfgm_common

    python db_json_exim.py --export-to db-dump.json

  3. See a cleaner version of the dump.

    cat db-dump.json | python -m json.tool | less

  4. Omit keyspace in the dump, for example, to share with Juniper Networks.

    python db_json_exim.py --export-to db-dump.json --omit-keyspace dm_keyspace

Restore Database from the Backup

Use the following steps to restore a system from a simple backup.

  1. Copy db-dump.json and contrail-api.conf to the host.

    mkdir /tmp/db-dump docker cp config_api_1:/etc/contrail/contrail-api.conf /tmp/db-dump/ docker cp config_api_1:/usr/lib/python2.7/site-packages/cfgm_common/db-dump.json /tmp/db-dump/

  2. Stop config services on all the controllers.

    docker stop config_svcmonitor_1

    docker stop config_devicemgr_1

    docker stop config_schema_1

    docker stop config_api_1

    docker stop config_nodemgr_1

    docker stop config_database_nodemgr_1

  3. Stop Cassandra on all the config-db controllers or verify it is already stopped.

    docker stop config_database_cassandra_1

  4. Stop Zookeeper on all the controllers or verify it is already stopped.

    docker stop config_database_zookeeper_1

  5. Stop Kafka on all controllers. Check analytics controllers.

    docker stop analytics_database_kafka_1

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

    cd /var/lib/docker/volumes/config_database_config_zookeeper

    cp -R _data/version-2/ version-2-save

  7. Wipe out the Zookeeper data directory contents on all the controllers.

    rm -rf _data/version-2/*

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

    cd /var/lib/docker/volumes/config_database_config_cassandra

    cp -R _data/ Cassandra_data-save

  9. Wipe out the Cassandra data directory contents on all controllers.

    rm -rf _data/*

  10. Start Zookeeper on all the controllers.

    docker start config_database_zookeeper_1

  11. Start Cassandra on all the controllers.

    docker start config_database_cassandra_1

  12. List docker image to the name/ID of config-api image.

    docker image ls | grep config-api

  13. Run a new docker using the name or ID of the config-api image.

    docker run --rm -it -v /tmp/db-dump/:/tmp/ --network host --entrypoint=/bin/bash ci-<repository>:5000/contrail-controller-config-api:5.0-latest

  14. Restore the data in new running docker.

    cd /usr/lib/python2.7/site-packages/cfgm_common python db_json_exim.py --import-from /tmp/db-dump.json --api-conf /tmp/contrail-api.conf

  15. Start Kafka on all controllers. Check analytics controllers.

    docker start analytics_database_kafka_1

  16. Start config services on all the controllers.

    docker start config_svcmonitor_1

    docker start config_devicemgr_1

    docker start config_schema_1

    docker start config_api_1

    docker start config_nodemgr

    docker start config_database_nodemgr

Example Backup and Restore in JSON

This section provides an example of a simple database backup and restore of a system that has three controllers with config-db and separate IPs with the following host IDs:

  • nodec53

  • nodec54

  • nodec55

Example: Perform Simple Database Backup in JSON Format

Example: Restore Database from the Backup

  1. Copy db-dump.json and contrail-api.conf to the host.

  2. Stop config services on all the controllers.

  3. Stop Cassandra on all the config-db controllers or verify it is already stopped.

  4. Stop Zookeeper on all the controllers or verify it is already stopped.

  5. Stop Kafka on all the controllers. Check analytics controllers.

  6. Stop Kafka on all the controllers. Check analytics controllers.

  7. Delete config Cassandra.

  8. Delete config Zookeeper.

  9. Start config Cassandra and Zookeeper on all the controllers.

  10. Run db_json_exim.py to restore the data from json dump.

  11. Start Kafka on all the controllers. Check analytics controllers.

  12. Start config services on all the controllers.