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
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.
The controller node for non-containerized Contrail is a virtual machine (VM).
The controller node for containerized Contrail is a controller container.
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
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
See a cleaner version of the dump.
cat db-dump.json | python -m json.tool | less
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.
Copy
db-dump.json
andcontrail-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/
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
Stop Cassandra on all the
config-db
controllers or verify it is already stopped.docker stop config_database_cassandra_1
Stop Zookeeper on all the controllers or verify it is already stopped.
docker stop config_database_zookeeper_1
Stop Kafka on all controllers. Check analytics controllers.
docker stop analytics_database_kafka_1
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
Wipe out the Zookeeper data directory contents on all the controllers.
rm -rf _data/version-2/*
Backup the Cassandra data directory on all the controllers.
cd /var/lib/docker/volumes/config_database_config_cassandra
cp -R _data/ Cassandra_data-save
Wipe out the Cassandra data directory contents on all controllers.
rm -rf _data/*
Start Zookeeper on all the controllers.
docker start config_database_zookeeper_1
Start Cassandra on all the controllers.
docker start config_database_cassandra_1
List docker image to the name/ID of
config-api
image.docker image ls | grep config-api
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
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
Start Kafka on all controllers. Check analytics controllers.
docker start analytics_database_kafka_1
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
[root@nodec54 ~]# docker exec -it config_api_1 bash (config-api)[root@nodec54 /root]$ cd /usr/lib/python2.7/site-packages/cfgm_common/ (config-api)[root@nodec54 /usr/lib/python2.7/site-packages/cfgm_common]$ python db_json_exim.py --export-to db-dump.json (config-api)[root@nodec54 /usr/lib/python2.7/site-packages/cfgm_common]$ cat db-dump.json | python -m json.tool |less { "cassandra": { "config_db_uuid": { "obj_fq_name_table": { "access_control_list": { <snip>
Example: Restore Database from the Backup
Copy
db-dump.json
andcontrail-api.conf
to the host.root@nodec54 ~]# mkdir /tmp/db-dump root@nodec54 ~]# docker cp config_api_1:/etc/contrail/contrail-api.conf /tmp/db-dump/ root@nodec54 ~]# docker cp config_api_1:/usr/lib/python2.7/site-packages/cfgm_common/db-dump.json /tmp/db-dump/
Stop config services on all the controllers.
[root@nodec53 ~]# docker stop config_schema_1 [root@nodec53 ~]# docker stop config_svcmonitor_1 [root@nodec53 ~]# docker stop config_devicemgr_1 [root@nodec53 ~]# docker stop config_nodemgr [root@nodec53 ~]# docker stop config_database_nodemgr root@nodec54~]# docker stop config_schema_1 [root@nodec54 ~]# docker stop config_svcmonitor_1 [root@nodec54 ~]# docker stop config_devicemgr_1 [root@nodec54 ~]# docker stop config_nodemgr [root@nodec54 ~]# docker stop config_database_nodemgr root@nodec55~]# docker stop config_schema_1 [root@nodec55 ~]# docker stop config_svcmonitor_1 [root@nodec55 ~]# docker stop config_devicemgr_1 [root@nodec55 ~]# docker stop config_nodemgr [root@nodec55 ~]# docker stop config_database_nodemgr
Stop Cassandra on all the
config-db
controllers or verify it is already stopped.[root@nodec53 ~]# docker stop config_database_cassandra_1 [root@nodec54 ~]# docker stop config_database_cassandra_1 [root@nodec55 ~]# docker stop config_database_cassandra_1
Stop Zookeeper on all the controllers or verify it is already stopped.
[root@nodec53 ~]# docker stop config_database_zookeeper_1 [root@nodec54 ~]# docker stop config_database_zookeeper_1 [root@nodec55 ~]# docker stop config_database_zookeeper_1
Stop Kafka on all the controllers. Check analytics controllers.
[root@nodec53 ~]# docker stop analytics_database_kafka_1 [root@nodec54 ~]# docker stop analytics_database_kafka_1 [root@nodec55 ~]# docker stop analytics_database_kafka_1
Stop Kafka on all the controllers. Check analytics controllers.
[root@nodec53 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec53 config_database_config_cassandra]# rm -rf _data/* [root@nodec54 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec54 config_database_config_cassandra]# rm -rf _data/* [root@nodec55 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec55 config_database_config_cassandra]# rm -rf _data/*
Delete config Cassandra.
[root@nodec53 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec53 config_database_config_cassandra]# rm -rf _data/* [root@nodec54 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec54 config_database_config_cassandra]# rm -rf _data/* [root@nodec55 ~]# cd /var/lib/docker/volumes/config_database_config_cassandra [root@nodec55 config_database_config_cassandra]# rm -rf _data/*
Delete config Zookeeper.
[root@nodec53 _data]# cd /var/lib/docker/volumes/config_database_config_zookeeper [root@nodec53 config_database_config_zookeeper]# rm -rf _data/version-2/* [root@nodec54 _data]# cd /var/lib/docker/volumes/config_database_config_zookeeper [root@nodec54 config_database_config_zookeeper]# rm -rf _data/version-2/* [root@nodec55 _data]# cd /var/lib/docker/volumes/config_database_config_zookeeper [root@nodec55 config_database_config_zookeeper]# rm -rf _data/version-2/*
Start config Cassandra and Zookeeper on all the controllers.
[root@nodec53 ~]# docker start config_database_zookeeper_1 [root@nodec53 ~]# docker start config_database_cassandra_1 [root@nodec54 ~]# docker start config_database_zookeeper_1 [root@nodec54 ~]# docker start config_database_cassandra_1 [root@nodec55 ~]# docker start config_database_zookeeper_1 [root@nodec55 ~]# docker start config_database_cassandra_1
Run
db_json_exim.py
to restore the data from json dump.root@nodec54 ~]# docker image ls | grep config-api root@nodec54 ~]# docker run --rm -it -v /tmp/db-dump/:/tmp/ --network host --entrypoint=/bin/bash ci-<repository>:5000/contrail-controller-config-api:5.0-latest (config-api)[root@nodec54 /root]$ cd /usr/lib/python2.7/site-packages/cfgm_common/ config-api)[root@nodec54 /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
Start Kafka on all the controllers. Check analytics controllers.
[root@nodec53 ~]# docker start analytics_database_kafka_1 [root@nodec54~]# docker start analytics_database_kafka_1 [root@nodec55~]# docker start analytics_database_kafka_1
Start config services on all the controllers.
[root@nodec53 ~]# docker start config_schema_1 [root@nodec53 ~]# docker start config_svcmonitor_1 [root@nodec53 ~]# docker start config_devicemgr_1 [root@nodec53 ~]# docker start config_nodemgr [root@nodec53 ~]# docker start config_database_nodemgr [root@nodec53 ~]# docker start config_api _1 [root@nodec54~]# docker start config_schema_1 [root@nodec54 ~]# docker start config_svcmonitor_1 [root@nodec54 ~]# docker start config_devicemgr_1 [root@nodec54 ~]# docker start config_nodemgr [root@nodec54 ~]# docker start config_database_nodemgr [root@nodec54 ~]# docker start config_api _1 [root@nodec55 ~]# docker start config_schema_1 [root@nodec55 ~]# docker start config_svcmonitor_1 [root@nodec55 ~]# docker start config_devicemgr_1 [root@nodec55 ~]# docker start config_nodemgr [root@nodec55 ~]# docker start config_database_nodemgr [root@nodec55 ~]# docker start config_api _1