-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create backup script on control nodes, add metadata for backupninja #19
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/usr/local/bin/contrail-cassandra-backup: | ||
file.managed: | ||
- user: root | ||
- group: root | ||
- mode: 755 | ||
- source: salt://opencontrail/files/contrail-cassandra-backup | ||
- template: jinja |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{% from "opencontrail/map.jinja" import database with context %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should strip empty lines by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this file doesn't need to be a jinja template at all. |
||
{% set node_fqdn = salt['grains.get']('fqdn') %} | ||
|
||
#!/bin/bash | ||
|
||
set -uef -o pipefail | ||
|
||
# Define vars | ||
BACKUP_DIR=/var/backups/cassandra | ||
DATA_DIR=/var/lib/cassandra/data | ||
NODETOOL=$(which nodetool) | ||
|
||
TODAY_DATE=$(date +%F) | ||
NODENAME="{{ node_fqdn }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
CONTROL_NODES_DB_TAG="OPENCONTRAIL_CONTROL_DB" | ||
BACKUP_SNAPSHOT_DIR="${BACKUP_DIR}/${CONTROL_NODES_DB_TAG}/${NODENAME}/${TODAY_DATE}/SNAPSHOTS" | ||
BACKUP_SCHEMA_DIR="${BACKUP_DIR}/${CONTROL_NODES_DB_TAG}/${NODENAME}/${TODAY_DATE}/SCHEMA" | ||
|
||
SNAPSHOT_NAME=snp-$(date +%F-%H%M-%S) | ||
DATE_SCHEMA=$(date +%F-%H%M-%S) | ||
|
||
DB_BIND_HOST="{{ database.bind.host }}" | ||
DB_BIND_PORT="{{ database.bind.port }}" | ||
CQL_SH="$(which cqlsh) ${DB_BIND_HOST} ${DB_BIND_PORT}" | ||
## List All Keyspaces | ||
declare -a KEYSPACE_LIST=( $( ${CQL_SH} -e "DESC KEYSPACES" | awk '{RS="\\s+"; if(NF>0){print}}' | sort ) ) | ||
|
||
# Make sure backup Directory exists | ||
mkdir -p "${BACKUP_SCHEMA_DIR}" | ||
mkdir -p "${BACKUP_SNAPSHOT_DIR}" | ||
|
||
# Dump cassandra version | ||
${NODETOOL} version > "${BACKUP_DIR}/${CONTROL_NODES_DB_TAG}/${NODENAME}/${TODAY_DATE}/.cassandra_version" | ||
# Remove previous snapshot in order to prevent disk usage increase | ||
${NODETOOL} clearsnapshot | ||
|
||
# SCHEMA BACKUP | ||
# Create directory inside backup SCHEMA directory. As per keyspace name. | ||
for VAR_KEYSPACE in ${KEYSPACE_LIST[*]} | ||
do | ||
mkdir -p "${BACKUP_SCHEMA_DIR}/${VAR_KEYSPACE}" | ||
# SCHEMA Backup - All Keyspace and All tables | ||
${CQL_SH} -e "DESC KEYSPACE ${VAR_KEYSPACE}" > "${BACKUP_SCHEMA_DIR}/${VAR_KEYSPACE}/${VAR_KEYSPACE}_schema-${DATE_SCHEMA}.cql" | ||
done | ||
|
||
# Create snapshots for all keyspaces | ||
${NODETOOL} snapshot -t "${SNAPSHOT_NAME}" | ||
|
||
###### Get Snapshot directory path | ||
declare -a SNAPSHOT_DIR_LIST=( $(find ${DATA_DIR} -type d -name snapshots) ) | ||
|
||
## Create directory inside backup directory. As per keyspace name. | ||
for SNP_PATH in ${SNAPSHOT_DIR_LIST[*]} | ||
do | ||
i=$(echo "${SNP_PATH}" | awk '{gsub("'${DATA_DIR}'/", "");print}') | ||
mkdir -p "${BACKUP_SNAPSHOT_DIR}/${i}" | ||
cp -prf "${SNP_PATH}/${SNAPSHOT_NAME}" "${BACKUP_SNAPSHOT_DIR}/${i}/" | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% set node_fqdn = salt['grains.get']('fqdn') %} | ||
backup: | ||
cassandra: | ||
fs_excludes: | ||
- /var/backups/cassandra/OPENCONTRAIL_CONTROL_DB/* | ||
fs_includes: | ||
- /var/backups/cassandra/OPENCONTRAIL_CONTROL_DB/{{ node_fqdn }}/ | ||
actions: | ||
- cmd: /usr/local/bin/contrail-cassandra-backup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not introducing new state (cassandra_backup.sls) but having this as a part of opencontrail.control